Recursion ANSWER MUST BE TYPED WITHIN THE QUESTIONS BELOW Re

Recursion

ANSWER MUST BE TYPED WITHIN THE QUESTIONS BELOW

Recursion

1. Determine what the following function calls return for recursive function func below.
    (4 pts.)

            public static int func(int n)

     {

        if(n == 1)

          return n;

        else

          return 1 + func(n-1);

           

      (a) func(1) = _________

      (b) func(4) = _________

2. Does func above perform down or bottom up computation? ___________________ (2 pts.)

3. Determine the result of the following function for recursive function func2 (4 pts.)

            public static void func2(int n)

     {

        if(n == 1)

          System.out.println(“*”);

        else

        {

          for (int i = 1; i <= n, i++)

             System.out.print(“*”);

          System.out.println();

          func2(n-1);

                   }

            }

4. Does func2 above perform down or bottom up computation? ___________________ (2 pts.)

Solution

Answer:

1)The given function calls return for recursive function values as below :

(a) func(1) = 1

(b) func(4) = 4

2. Does func above perform down or bottom up computation? down

3)The result of the following function for recursive function func2 is as below :

For every n value there would be stars symbols of n,n-1,n-2,n-3 ........so on respectively seperated by a space.

For example : if n=4 the stars will be displayed as **** *** ** * seperated by a space.

4)Does func2 above perform down or bottom up computation? bottom up

Recursion ANSWER MUST BE TYPED WITHIN THE QUESTIONS BELOW Recursion 1. Determine what the following function calls return for recursive function func below. (4
Recursion ANSWER MUST BE TYPED WITHIN THE QUESTIONS BELOW Recursion 1. Determine what the following function calls return for recursive function func below. (4

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site