Data Structures

1:

If memory for the run-time stack is only 150 cells(words), how big can N be in Factorial(N) before encounterring stack overflow?

A.

24

B.

12

C.

26

D.

50

 

Answer : C

Explanation :

Given that, the size of a run time stack is of 150 cells (words). The arguments to be evaluate the factorial are placed on the stack. A function call is made to calculate the factorial. Subroutine is executed for each time the function call is made. Each funcall creates a stack frames of co words (Cells), 2 words for n, 2 words for program counter (PC) and 2 words for some other information.
The value of n should be such that, the size of stack should not exceed 150 cells. If we consider the value of n to be 26, it executes 25 procedure calls each of it with 6-word stack frame.
In this case totalnumber of words of stack space would be 150 (6 words × 25 procedure calls = 150) cells.
Therefore, value of n will be 26 is n! before encountering a stack overflow for the stack of size 150 cells (words)

rama said: (10:07pm on Wednesday 13th February 2013)
please explain how 66 and also if factorial is using recursion or simple.

Write your comments here:


Report Error
 

Option: A

Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here.