Page 422 - Computer science 868 Class 12
P. 422

Let’s Revisit


                    ♦ Recursion is a programming technique where the function calls itself repeatedly until a exit condition called the base case is
                   achieved.
                    ♦ Base case is the condition where 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 in which the function calls itself repeatedly with changed value of argument.
                    ♦ 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 stack.
                    ♦ Direct recursion is the normal recursive technique where a function calls itself from its own body.
                    ♦ Indirect recursion is a coding technique where 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.
                    ♦ It 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 ………………… .
                    a.  Base case                                   b.  Worst case
                    c.  Average case                                d.  Recursive case
                  2.  Recursion is similar to which of the following?
                     a.  Switch case                                b.  Loop
                    c.  if-else                                     d.  if-else if-else
                  3.  Which of the following statements is true?
                    a.  Recursion uses FIFO concept.
                    b.  Recursion uses more memory compared to iteration.
                    c.  Recursion uses less memory 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 upto 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)
                  5.  A function calls a second function which in turn calls its caller method is an example of ………………… .
                    a.  direct recursion                            b.  tail recursion
                    c.  indirect recursion                          d.  heap recursion


                 Answers
                 1.  a           2.   b          3.  b          4.  c           5.  c


              B.  Fill in the blanks:
                  1.  Fill in the blanks to print the sum of digits of a number ‘num’ using recursive method int sum of digit (int n)
                       int sumofdigit(int n)
                       {
                       int dig;

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