GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Placement Papers  >  TCS

 Print  |  
Question:  given g(0)=1,g(1)=-1and g(n)=g(n-1)+g(n-2),find(6).



February 02, 2008 02:35:00 #2
 abhishek76   Member Since: February 2008    Total Comments: 1 

RE: given g(0)=1,g(1)=-1and g(n)=g(n-1)+g(n-2),find(6).
 
we can write g(6) as g(5)+g(4) (since g(n)=g(n-1)+g(n-2))
again 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=0(as given above)
     therefore,g(3)= 0-1=-1
                     g(4)=-1+0=-1
                     g(5)=-1-1=-2
   therefore, g(6)=g(5)+g(4)=-2-1=-3(ans)
     

 

Back To Question