0% found this document useful (0 votes)
6 views2 pages

Example Fib T (N)

Uploaded by

227567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Example Fib T (N)

Uploaded by

227567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Algorithms 15-2-2022

Example int fib(int n)

Fib(n)= fib(n-1)+fib(n-2), n>1 {


if (n <= 1)
fib(0) =0, return n;
return fib(n-1) + fib(n-2);
fib(1) =1 } T(n) = T(n-1) + T(n-2) + C
tn = tn-1+tn-2, n>=2,

t0 = 0,
tn= tn-1+tn-2, n>=2,
t1 = 1
t0=0, n=0

t1=1, n=1

x2 - x - 1 = 0

Roots =

r1 = r2=

Work with Steps for x2 - x - 1 = 0


Algorithms 15-2-2022

tn = c1.r1n+ c2.r2n

= c1.( )n+ c2.( )n = O(2n)

t0=0=c1+c2
t1=1 = c1.( ) + c2.( )
c1 = 1/(√5)
c2 = -1/(√5)

tn = 1/√5 ( ) n- 1/√5 ( )n

t2=t1+t0=1
t3=t2+t1=2
t4=t3+t2=3

t4 = 1/√5.( )4 - 1/√5 .( )4 = 3

You might also like