587 views
1 votes
1 votes

How is the max possible value of n is 12? We will have to store T(0) and T(1) in stack too, so we can call f(11) at max which will require T(10) and T(9) and then we will store f(11) in stack. But if we call f(12) we wont be able to store it as overflow will occur.

2 Answers

1 votes
1 votes

$T_{0}=0\ ,\ T_{1}=1\ given\ in\ question $

Let's there is 

$T{_{2}}=T{_{1}}+T {_{0}}$

$T{_{1}}\ will\ call\ first\ and\ return\ 1\ and\ make\ space\ for \ T{_{0}}$

$it\  means\ T{_{1}}\ and\ T{_{0}}\ will\ share\ same\ space$

$say\ n=4$

$T_{1}$
$T_{2}$
$T_{3}$
$T_{4}$

 

$T_{1}\ and\ T_{0}\ values\ are\ store\  in\ table\ so \ no\ need\ to\ evaluate\ them.$

$in\ this\ question\ maximum\ number\ of\ function\ call\ before\ stack\ overflow\ is\ $

$n*4=48$

n=12

edited by
0 votes
0 votes
Let n = 4                   T(4)

                     T(3)               T(2)

               T(2)      T(1)     T(1)    T(0)

          T(1)    T(0)

So for n=4  4 levels of stack needed. now for 12 levels stack n=12

Related questions

2 votes
2 votes
0 answers
4
Akash Mishra asked Jul 26, 2017
970 views
The correct answer to the following question is 24. Please explain.