1.If g (0)=g (1)=1And g (n)= g (n-1) + g (n –2) find g (6);tell me the solution

This question is related to TCS Interview

Showing Answers 1 - 28 of 28 Answers

Kayalvizhi

  • Oct 3rd, 2006
 

Given g(0) = g(1) = 1.

To find: g(6)

g(n) = g(n-1) + g(n-2)

g(2) = g(1) + g(0) = 1 + 1 = 2

g(3) = g(2) + g(1) = 2 + 1 = 3

g(4) = g(3) + g(2) = 3 + 2 = 5

g(5) = g(4) + g(3) = 5 + 3 = 8

g(6) = g(5) + g(4) = 8 + 5 = 13.

7

venkatesh

  • Oct 4th, 2006
 

8

  Was this answer useful?  Yes

sreetama dutta

  • Oct 8th, 2006
 

which is the answer ..13 or 7?.if 7 is the answer how do u get that- counting the total steps or else?

  Was this answer useful?  Yes

Santosh

  • Oct 17th, 2006
 

Answer is 13 because

g(6)=g(5)+g(4)

=(g(4)+g(3))+(g(3)+g(2))

=((g(3)+g(2))+(g(2)+g(1)))+(g(2)+g(1))+(g(1)+g(0)))

=(((g(2)+g(1))+(g(1)+g(0)))+(g(1)+g(0))+g(1)))+((g(1)+g(0))+g(1)+(g(1)+g(0))

=((((g(1)+g(0))+(g(1)+g(0)))+(g(1)+g(0))+g(1)))+((g(1)+g(0))+g(1)+(g(1)+g(0))

  Was this answer useful?  Yes

Ram

  • Jan 21st, 2007
 

The answer is 13.

It is based on method of recursion.

  Was this answer useful?  Yes

su2008

  • Jul 28th, 2008
 

g(5)=g(4)-g(3)
           = -1-(-1)
          =  -1+1
          =  0
 

g(4)=g(3)-g(2)
           = -1-0
           = -1        

g(3)=g(2)-g(1)
          = 0-1
          = -1       

g(2)=g(1)-g(0)
          =1- 1
          =0


g(6)=g(5)-g(4)
         =0 -  (-1 )
        =0+1
         =1      

  Was this answer useful?  Yes

renesha

  • Sep 18th, 2008
 

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

g(3) =g(3-1) + g(3-2)  = g(2) + g (1)= 2  + 1= 3
     
g(4) =g(4-1) + g(4-2)  = g(3) + g (2)= 3  + 2= 5 

g(5) =g(5-1) + g(5-2)  = g(4) + g (3)= 5  + 3= 8

g(6) =g(6-1) + g(6-2)  = g(5) + g (4)= 8  + 5= 13

Noob1

  • Aug 13th, 2010
 

g(6)= g(5)+g(4)

g(4)= g(3)+g(2)

g(2)= g(1)+g(0)= 2    (Given in ques g(0)=g(1)=1)

So, g(3)= g(2)+g(1)= 2+1= 3

Also, g(4)= g(3)+g(2)= 3+2= 5

Similarly, g(5)= g(4)+g(3)= 5+3=8

And hence, g(6)= g(5)+g(4)= 8+5= 13 -ANS

  Was this answer useful?  Yes

tanmoytt

  • Aug 14th, 2010
 

g(6)=g(5)+g(4)
g(5)=g(4)+g(3)
g(4)=g(3)+g(2)
g(3)=g(2)+g(1)
g(2)=g(1)+g(0)=1+1=2
S0, g(3)=2+1=3
g(4)=3+2=5
g(5)=5+3=8
g(6)=8+5=13

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions