Page 386 - Cs_withBlue_J_C11_Flipbook
P. 386

13


                                                                                 RECURSION

















                       Learning Objectives


                   13.1  Concept of Recursion                         13.2  Types of Recursion
                   13.3  Simple Recursive Methods




              The floor art, known by various names - rangoli, kolam, alpana (or alpona), etc., is
              a part of Indian tradition drawn daily early in the morning especially on auspicious
              events as a sign of welcome. It is a design made of different geometric patterns like
              dots, lines, curves, and loops. If we minutely watch the design, then we find that the
              whole diagram is a repetition of similar smaller designs placed one beside another
              in different patterns.

              The basic drawing starts from the dots. By joining the dots in a definite pattern,
              we achieve this intricate expression.

              The fractals (patterns that repeat forever) are thus created by repeating a simple
              process over and over again, or in other words, we can say that they follow the
              concept of recursion.


                  13.1 CONCEPT OF RECURSION
              In Java, we can call functions from different functions. Recursion is a programming technique in which a function calls
              itself. This technique helps us to break complex problems into simple problems which are easier to solve. A function
              that implements recursion is called a recursive function.



                                                             Definition
                   Recursion is a programming technique in which the function calls itself repeatedly until an exit condition called the
                   base case is achieved.



              Let us explain the concept with a simple example.
                                       n
              Suppose, we want to find a . If we design a loop then we define a variable whose value changes from 1 to n and
              multiplying the term with the product ‘n’ number of times produces the required result as demonstrated below.
              p = a × a × a × a ×........... n times.


                384384  Touchpad Computer Science-XI
   381   382   383   384   385   386   387   388   389   390   391