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

asked in Algorithms by Loyal (3.9k points)   | 115 views

1 Answer

+2 votes
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 (18.2k 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 Mar 2017
  1. rude

    4768 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2910 Points

  4. Kapil

    2732 Points

  5. Debashish Deka

    2502 Points

  6. 2018

    1544 Points

  7. Vignesh Sekar

    1422 Points

  8. Akriti sood

    1322 Points

  9. Bikram

    1290 Points

  10. Sanjay Sharma

    1106 Points

Monthly Topper: Rs. 500 gift card

21,502 questions
26,826 answers
61,077 comments
23,127 users