Docsity

Fibonacci Sequences-Advance Analysis Design-Lecture Slides, Slides of Design and Analysis of Algorithms

Partial preview of the text

Download Fibonacci Sequences-Advance Analysis Design-Lecture Slides and more Slides Design and Analysis of Algorithms in PDF only on Docsity!

Lecture No. 6

Fibonacci Sequences

(Natural Models)

In this lecture we will cover the following:•

Fibonacci Problem and its Sequence

Construction of Mathematical Model

Explicit Formula Computing FibonacciNumbers

Recursive Algorithms

Generalizations of Rabbits Problem andConstructing its Mathematical Models

Applications of Fibonacci Sequences

Today Covered

Statement:•

Start with a pair of rabbits, one male and one female,born on January 1.

Assume that all months are of equal length and thatrabbits begin to produce two months after their own birth.

After reaching age of two months, each pair producesanother mixed pair, one male and one female, and thenanother mixed pair each month, and no rabbit dies.How many pairs of rabbits will there be after one year?

Answer:

The Fibonacci Sequence!

Fibonacci’s Problem

Construction of Mathematical Model

Since F

k

= F

k-

+ F

k-

F

0

= 0, F

1

F

2

= F

1

+ F

0

F

3

= F

2

+ F

1

F

4

= F

3

+ F

2

F

5

= F

4

+ F

3

F

6

= F

5

+ F

4

F

7

= F

6

+ F

5

F

8

= F

7

+ F

6

F

9

= F

8

+ F

7

F

10

= F

9

+ F

8

F

11

= F

10

+ F

9

F

12

= F

11

+ F

10

Computing Values using Mathematical Model

2

1

k

k

k

F

F

F

1

condition

initial

with

2

1

0

2

1

     

F

F k

F

F

F

k

k

k

Theorem:The fibonacci sequence F

0

,F

1

, F

2

,…. Satisfies

the recurrence relation

Find the explicit formula for this sequence.Solution: Let t

k

is solution to this, then characteristic equation

The given fibonacci sequence

Explicit Formula Computing Fibonacci Numbers

2

t

t

 

1

2

1

2

5

1

2

5

1

2

5

1

2

5

1

F

1

Now

1

1

       

  

  

  

  

F

D

C

D

C n

n

n

D
HenceF
5 1 , 5 1 C
get
usly we
simultaneo
and
Solving

n

Fibonacci Sequence

After simplifying we getwhich is called the explicit formula for theFibonacci sequence recurrence relation.

n

n

F

n

Fibonacci Sequence

5 1

5 1

F

then

2

5

1

and

2

5

1

Let

n

n

n

  

  

  

  

 

Fibo-R(

n

if

n

then

if

n

then

else

Fibo-R(

n

-1) + Fibo-R(

n

Recursive Algorithm Computing Fibonacci Numbers

Terminating conditions
Recursive calls
Least Cost: To find an asymptotic bound of computationalcost of this algorithm, we can use a simple trick to solve thisrecurrence containing big oh expressions
Simply drop the big O from the recurrence, solve therecurrence, and put the O back. Our recurrencewill be refined to

2 n ) 2 ( ) 1 (

if

n

T

n

T

n

O

n

T

Running Time of Recursive Fibonacci Algorithm

2 n ) 2 ( ) 1 (

if

n

T

n

T

n

n

T

Guess that F

n+

is the least cost to solve this

recurrence. Why this guess?

n

0, T(n)

F

n+

then F

n+

will be minimum cost for this recurrence

We prove it by mathematical induction

Base CaseThere are two base cases

For n = 0, T(0) = 1 and F

1

hence T(0)

F

1

For n = 1, T(1) = 1 and F

2

hence T(1)

F

2

Running Time of Recursive Fibonacci Algorithm

Inductive HypothesisLet us suppose that statement is true some k

1

T(k)

F

k+

, for k =0, 1, 2,... and k

1

Now we show that statement is true for k + 1

Now, T(k + 1) = T(k) + T(k -1)

By definition on T(n)

T(k + 1) = T(k) + T(k -1)

F

k+

  • F

k

= F

k+

Assumption

T(k + 1)

F

k+

Hence the statement is true for k + 1.

We can now say with certainty that running time ofthis recursive Fibonacci algorithm is at least

(F

n+

).

Running Time of Recursive Fibonacci Algorithm

W say that two quantities, x and y, (x < y), are inthe golden ratio if the ratio between the sum, x + y,of these quantities and the larger one, y, is thesame as the ratio between the larger one, y, andthe smaller one x.

Mathematicians have studied the golden ratiobecause of its unique and interesting properties.

Golden Ratio

62 .

1

y x

y

y

x

Golden Ratio 0

1

1

1

1

i.e.

y

y

x

and

y

x

course

of

1

,

62 .

0

1

62 .

1

2

5

1

2

     

     

y x

x y

1 

1