Page 422 - Cs_withBlue_J_C11_Flipbook
P. 422

28
              35
              81
              44
              67
              92
              17
              The largest number is: 92

                            Let’s Revisit


                    ♦ Recursion is a programming technique in which the function calls itself repeatedly until an exit condition called the base case is
                   achieved.
                    ♦ The base case is the condition in which the function stops calling itself. This is a very important part of recursion construct
                   otherwise the function will call itself infinitely until the program crashes.
                    ♦ The recursive case is the condition in which the function calls itself repeatedly with the changed value of the arguments.
                    ♦ Recursion works on LIFO (Last In First Out) principle.
                    ♦ When a recursive method is called, the computer creates a new stack of frames and places it at the top of the stack.
                    ♦ Direct recursion is a normal recursive technique in which a function calls itself from its own body.
                    ♦ Indirect recursion is a coding technique in which the first method calls the second method which in turn calls the first method in
                   a circular fashion.
                    ♦ Recursion is used extensively in back tracking algorithm, tree traversal, etc.
                    ♦ Recursion consumes a lot of memory and is a slow process.



                                                           MIND DRILL






                   Solved Questions



              A.  Tick ( ) the correct option:
                  1.  In recursion, the condition after which the function will stop calling itself is known as the …………………… .
                         a.  Base case                              b.  Worst case
                    c.  Average case                                d.  Recursive case
                  2.  Which of the following technique is similar to recursion?
                        a.  Switch Case                             b.  Loop
                    c.  If-else                                     d.  If-else-if
                  3.  Which of the following statements is true?
                       a.  Recursion uses FIFO concept.                 b.  Recursion uses more memory as compared to iteration.
                       c.  Recursion uses less memory as compared to iteration.   d.  Recursion works faster than iteration.
                  4.  Which of the following recursive formula can be used to find the sum of all natural numbers up to a given number?
                       a.  sum (n) = n + sum (n%1)                  b.  sum (n) = n + sum (n/2)
                       c.  sum (n) = n + sum (n-1)                   d.  sum (n) = n + sum (n*1)
                Answers
                   1.  a     2.  b     3.  b     4.  c



                420420  Touchpad Computer Science-XI
   417   418   419   420   421   422   423   424   425   426   427