Question

# #data structures Look at square numbers one more time:    square(1) = 1    square(N) =...

#data structures
Look at square numbers one more time:
square(1) = 1
square(N) = square(N-1) + 2N -1
Assume the definition has been implemented correctly. How many stack frames for square() will be created on the computer memory stack in RAM if main() calls square(5)?

A) 1

B) 3

C) 5

D) 6

Answer : Correct Option is Option(C) ie. 5.

5 stack frames for square() will be created on the computer memory stack in RAM if main() calls square(5).

Explanation :

When square(5) called from the main() , then the above recursive function works and it will go like this : square(5), then square(4), then square(3), then square(2), then square(1) and then stops as the base condition goes true.

Hence total stacks frames created is 5.

Hence,

Option(A) is Incorrect. The total stacks created on computer memory is not 1.

Option(B) is Incorrect.The total stacks created on computer memory is not 3.

Option(C) is Correct. The total stacks created on computer memory is 5.

Option(D) is Incorrect. The total stacks created on computer memory is not 6.

So,

Correct Option is Option(C) ie. 5.

#### Earn Coins

Coins can be redeemed for fabulous gifts.