CS111 C++ Practice Quiz #4

Recursion




  1. is the phenomemnon of a function referencing itself.

  2. Name and describe the two parts of a recursive definition of a function.




  3. TRUE or FALSE : A nonrecursive function for computing some value may execute more rapidly than a recursive function that computes the same value.



    For the remaining questions, use the following recursive function:
        int F (int n){
          if (n == 0)
            return 0;
          else
            return n + F(n-1);
        }

      • What final value is returned from the function call F(5)?

      • What final value is returned from the function call F(0)?

      • What final value is returned from the function call F(-1).
      • Suppose + is changed to * in the recursive step.
        What final value is returned from the function call F(5)?




Answers
  1. recursion

  2. TRUE
  3. 15
  4. 0
  5. Infinite recursion.
  6. 0