Computer Science: Programming with a Purpose Week 6 Quiz Answer

Computer Science Programming with a Purpose Week 6 Quiz Answer

Computer Science: Programming with a Purpose Week 6 Quiz Answer


In this article i am gone to share Coursera Course Computer Science: Programming with a Purpose Week 6 | Recursion Quiz Answer with you..


Recursion



Question 1)
Which of the following are broadly useful approaches for solving problems by combining solutions to smaller subproblems? Mark all that apply.
  • recursion
  • simulation
  • exponential waste
  • dynamic programming
  • conditional programming



Question 2)
Give the value of Q2(6)

public static int Q2(int n)
  {
   if (n <= 0) return 1;
     return 1+ Q2(n-2) +Q2(n-3);
  }

  • 13



Question 3)
Give the 10th integer printed by a call to Q3(6).

public static void Q3(int n)
{
  if (n <= 0) return;
  stdout.println(n)
  Q3(n-2);
  Q3(n-3);
  Stdout.println(n);
}


  • 13



Question 4)
Give the number of integers printed bya call to Q4(7).

public static void Q4(int n)
{
  if (n <= 0) return;
  stdout.println (n) ;
  Q4 (n-2);
  Q4(n-3);
  stdout.println (n);
}


  • 16



Question 5)
Give the value of Q5(8).

{
  int[] b = new int[n+1];
  b[0] 1;
  for (int i = 2; i <=n; i++)
  {
     b[i] = 0;
     for (int j = 0; j< i; j++)
          b[i] += b[jl;
  }
   return b[n];
}


  • 64








Post a Comment

0 Comments