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).



October 10, 2007 01:56:58 #1
 santosh   Member Since: Visitor    Total Comments: N/A 

RE: given g(0)=1,g(1)=-1and g(n)=g(n-1)+g(n-2),find(6)...
 
#  substitute n=6
    
     => g(6) = g(5)+g(4)----------------(1)
#  sub n=5
    => g(5) = g(4)+g(3)-----------------(2)

# sub n=4
    => g(4) = g(3)+g(2)------------------(3)
#sub n=3
   => g(3)= g(2)+g(1)--------------------(4)
# sub n=2
    => g(2)= g(1)+g(0)--------------------(5)
 
so ,
       g(2) = 0;
        g(3)= -1;
        g(4) = -1;
         g(5)= -2;
       

         g(6) = -3;


another method:

g(6) = 5*g(1)+g(0)


so generalised solution is    g(a) = (a-1)*g(1)  +  g(o)    where a is to find for the given equation g(n) = g(n-1)+g(n-2)
     

 

Back To Question