GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
79 views

asked in Algorithms by Active (1.2k points)   | 79 views

1 Answer

+1 vote
Best answer
okay,it can be solved using Dynamic Programming

and once one is computed, it can be easily found by going through the table.

and we can write it like

T(12)=T(10)+T(9)

T(10)=T(8)+T(7)

T(9)=T(7)+T(6)

T(8)=T(6)+T(5)

T(7)=T(5)+T(4)

T(6)=T(4)+T(3)

T(5)=T(3)+T(2)

T(4)=T(2)+T(1)

T(3)=T(1)+T(0)

T(2)=T(0)+T(-1)

We need one function call for each unique T(x)

here we need function calls T(-1),T(0),T(1),T(2,)T(3),T(4),T(5),T(6),T(7),T(8),T(9),T(10),T(12)

13 function calls

so it should be the answer
answered by Veteran (12.5k points)  
selected by
Are..it was this easy..I was complicating it unnecessarily. Thanks :)
Happens!
Btw,whats the answer?

yes..ur answer is correct. But the explaination was this.

ya, they did the same! i did table manner, they did tree approach! do not worry. Same thing.Even they missed something in last level
ok..actually they did not count all function calls, and counted T(5) twice, so I assumed it to be wrong.
^ they r consistent :P
Top Users Jan 2017
  1. Debashish Deka

    8968 Points

  2. sudsho

    5326 Points

  3. Habibkhan

    4798 Points

  4. Bikram

    4532 Points

  5. Vijay Thakur

    4486 Points

  6. saurabh rai

    4222 Points

  7. Arjun

    4196 Points

  8. santhoshdevulapally

    3808 Points

  9. Sushant Gokhale

    3596 Points

  10. Kapil

    3486 Points

Monthly Topper: Rs. 500 gift card

19,212 questions
24,104 answers
53,150 comments
20,319 users