Question: 1. Consider the following function: void quiz(int i) { if (i>1) { quiz(i/2); quiz(i/2); } print (*); } What kind of recursive function is this?

1. Consider the following function:

void quiz(int i)

{

if (i>1)

{

quiz(i/2);

quiz(i/2);

}

print ("*");

}

What kind of recursive function is this?

A. non-tail recursion

B. tail recursion

C. both tail and non-tail recursion

D. no correct answer was given

------------------------------------------------------------------------------------------------------

2. In the most common scenario, what happend when a recursive function call is made?

A. an activation record for this function is pushed into the runtime stack

B. an activation record for this function is popped from the runtime stack

C. Both A and B

D. none of the above

------------------------------------------------------------------------------------------------------

3. Consider the following function:

algorithm super_write (int number)

if (number < 0)

println ("-");

super_write(abs(number));

else if (number <10)

println(number);

else

super_write(number/10);

println(number%10);

What values of number are directly handled by the ground/anchor case?

A. number >= 0 && number < 10

B. number < 0

C. number < 10

D. number > 10

------------------------------------------------------------------------------------------------------

4. Consider the following function:

void test_b(int n)

{

if (n>0)

test_b(n-2);

print(n);

}

What is printed by the call test_b(4)?

A. 0 2

B. 4 2 0

C. 0 2 4

D. 4 2

E. 2 4

------------------------------------------------------------------------------------------------------

5. Consider the following function:

void test_a(int n)

{

print n;

if(n>0)

test_a(n-2);

}

What is printed by the call test_a(4)?

A. 4 2 0

B. 0 2 4

C. 4 2

D. 0 2

E. 2 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!