Fibonacci Sequences-Advance Analysis Design-Lecture Slides, Slides for Advance Analysis Design. Bengal Engineering & Science University

Advance Analysis Design

Description: This course object is to design and analysis of modern algorithms, different variants, accuracy, efficiency, comparing efficiencies, advance designing techniques. In this course algorithm will be analyse using real world examples. This lecture includes: Fibonacci, Sequences, Natural, Model, Construction, Explicit, Formula, Recursive, Algorithm, Applications, Model
Showing pages  1  -  2  of  33
The preview of this document ends here! Please or to read the full document or to download it.
Document information
Uploaded by: parnavi
Views: 1000+
Downloads : 0
University: Bengal Engineering & Science University
Upload date: 06/08/2012
Embed this document:

Lecture No. 6

Fibonacci Sequences (Natural Models)

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

In this lecture we will cover the following:

• Fibonacci Problem and its Sequence

• Construction of Mathematical Model

• Explicit Formula Computing Fibonacci Numbers

• Recursive Algorithms

• Generalizations of Rabbits Problem and Constructing its Mathematical Models

• Applications of Fibonacci Sequences Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Today Covered

docsity.com

• By studying Fibonacci numbers and constructing Fibonacci sequence we can imagine how mathematics is connected to apparently unrelated things in this universe.

• Even though these numbers were introduced in 1202 in Fibonacci’s book Liber abaci, but these numbers and sequence are still fascinating and mysterious to people of today.

• Fibonacci, who was born Leonardo da Pisa gave a problem in his book whose solution was the Fibonacci sequence as we will discuss it today.

Fibonacci Sequence

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

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 that

rabbits begin to produce two months after their own birth. • After reaching age of two months, each pair produces

another mixed pair, one male and one female, and then another mixed pair each month, and no rabbit dies. How many pairs of rabbits will there be after one year?

Answer: The Fibonacci Sequence! 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, . . .

Fibonacci’s Problem

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Construction of Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Total pairs at level k = Total pairs at level k-1 + Total pairs born at level k (1)

• Since Total pairs born at level k = Total pairs at level k-2 (2)

• Hence by equation (1) and (2) Total pairs at level k = Total pairs at level k-1 + Total pairs at level k-2

• Now let us denote Fk = Total pairs at level k

• Now our recursive mathematical model will become Fk = Fk-1 + Fk-2

Construction of Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Since Fk = Fk-1 + Fk-2 F0 = 0, F1= 1 • F2 = F1 + F0= 1 + 0 = 1 • F3 = F2 + F1= 1 + 1 = 2 • F4 = F3 + F2= 2 + 1 = 3 • F5 = F4 + F3= 3 + 2 = 5 • F6 = F5 + F4= 5 + 3 = 8 • F7 = F6 + F5= 8 + 5 = 13 • F8 = F7 + F6= 13 + 8 = 21 • F9 = F8 + F7= 21 + 13 = 34 • F10 = F9 + F8= 34 + 21 = 55 • F11 = F10 + F9= 55 + 34 = 89 • F12 = F11 + F10= 89 + 55 = 144 . . .

Computing Values using Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

21   kkk FFF

1 condition initialwith 2

10

21

  

FF kFFF kkk

Theorem: The fibonacci sequence F0,F1, F2,…. Satisfies the recurrence relation

Find the explicit formula for this sequence. Solution:

Let tk is solution to this, then characteristic equation

The given fibonacci sequence

Explicit Formula Computing Fibonacci Numbers

012  tt Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

2 51 ,

2 51

2 411

21 

 

 

tt

t

Fibonacci Sequence

For some real C and D fibonacci sequence satisfies the relation

  0 1 0 F

2

51 2

51

0

0 2

51 2

51

0

0

00

0

 

 

  

   

  

  

 

  

  

  

  

FDC DC

DCF

n

nDCF nn

n

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

  1 2 1 2

51 2

51

2

51 2

51F

1 Now

1

1

 

 

 

  

   

  

  

FDC

DC

n

   

nn

D

 

  

   

  

 

  

   

  





52 51

5 1

2 51

5 1F

Hence 5

1, 5

1C

get usly wesimultaneo 2 and 1 Solving

n

Fibonacci Sequence

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

After simplifying we get

which is called the explicit formula for the Fibonacci sequence recurrence relation.

nn

 

  

   

  

  

2 51

5 1

2 51

5 1Fn

Fibonacci Sequence

5

1 5

1F

then 2

51 and 2

51Let

nn n 

 

  

  

  

   

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Example: Compute F3

then 2

51 and 2

51 where 5

1 5

1F Since nnn  

  

  

  

   

33

3 2 51

5 1

2 51

5 1F 

  

   

  

  

Verification of the Explicit Formula

 

  

   

  

  

8 555.1.35.1.31

5 1

8 555.1.35.1.31

5 1F Now,

22

3

   555.1.35.1.31 5.8

1555.1.35.1.31 5.8

1F3 

  2555.1.35.1.31555.1.35.1.31 5.8

1F3 

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Fibo-R(n) if n = 0

then 0 if n = 1

then 1 else Fibo-R(n-1) + Fibo-R(n-2)

Recursive Algorithm Computing Fibonacci Numbers

Terminating conditions

Recursive calls

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Least Cost: To find an asymptotic bound of computational cost of this algorithm, we can use a simple trick to solve this recurrence containing big oh expressions

• Simply drop the big O from the recurrence, solve the recurrence, and put the O back. Our recurrence

will be refined to

2 n )2()1(

2 if )1( )(   

 

nTnT

nO nT

Running Time of Recursive Fibonacci Algorithm

2 n )2()1(

2 if 1 )(   

 

nTnT

n nT

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Construction of Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Guess that Fn+1 is the least cost to solve this recurrence. Why this guess?  n  0, T(n)  Fn+1

then Fn+1 will be minimum cost for this recurrence • We prove it by mathematical induction Base Case There are two base cases

For n = 0, T(0) = 1 and F1 = 1, hence T(0)  F1 For n = 1, T(1) = 1 and F2 = 1, hence T(1)  F2

Running Time of Recursive Fibonacci Algorithm

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Inductive Hypothesis Let us suppose that statement is true some k  1

T(k)  Fk+1 , 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)  Fk+1 + Fk = Fk+2 Assumption T(k + 1)  Fk+2

• Hence the statement is true for k + 1. • We can now say with certainty that running time of

this recursive Fibonacci algorithm is at least (Fn+1).

Running Time of Recursive Fibonacci Algorithm

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Now we have proved that T(n)  Fn+1 , n  0 (1)

• We already proved in solution to recursive relation that

It can be easily verified that Fn  n/5  (3/2)n

From the equations (1) and (2), T(n)  Fn+1  Fn  (3/2)n

Hence we can conclude that running time of our recursive Fibonacci Algorithm is:

T(n) =  (3/2)n

Running Time of Recursive Fibonacci Algorithm

(2) 2

51 and 2

51 w 5

1 5

1F nnn  

  

  

  

   here

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

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

• Mathematicians have studied the golden ratio because of its unique and interesting properties.

Golden Ratio

62.1 x y

y yx

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Golden Ratio

01 1

1 1

i.e. y

yx andy x course of

1 ,62.01

62.1 2

51

2 

 

 

 

 

 



x y

y x

1

1

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Recursion Tree

Drawback in Recursive Algorithms

F(n)

F(n-1) F(n-2)

F(0) F(1)

F(n-2) F(n-3) F(n-3) F(n-4)

F(1) F(0)

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

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 that

rabbits begin to produce two months after their own birth. • After reaching age of two months, each pair produces

two other mixed pairs, two male and two female, and then two other mixed pair each month, and no rabbit dies. How many pairs of rabbits will there be after one year?

Answer: Generalization of Fibonacci Sequence! 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, . . .

Generalization of Rabbits Problem

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Construction of Mathematical Model

F0 = 0

F1 = 1

F2 = 1

F3 = 3

F4 = 5

F5 = 11

F6 = 21

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Total pairs at level k = Total pairs at level k-1 + Total pairs born at level k (1)

• Since Total pairs born at level k =

2 x Total pairs at level k-2 (2) • By (1) and (2), Total pairs at level k =

Total pairs at level k-1 + 2 x Total pairs at level k-2 • Now let us denote

Fk = Total pairs at level k • Our recursive mathematical model:

Fk = Fk-1 + 2.Fk-2 • General Model (m pairs production): Fk = Fk-1 + m.Fk-2

Construction of Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Recursive mathematical model (one pair production)

Fk = Fk-1 + Fk-2 • Recursive mathematical model

(two pairs production) Fk = Fk-1 + 2.Fk-2

• Recursive mathematical model (m pairs production)

Fk = Fk-1 + m.Fk-2

Generalization

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Since Fk = Fk-1 + 2.Fk-2 F0 = 0, F1 = 1 • F2 = F1 + 2.F0= 1 + 0 = 1 • F3 = F2 + 2.F1= 1 + 2 = 3 • F4 = F3 + 2.F2= 3 + 2 = 5 • F5 = F4 + 2.F3= 5 + 6 = 11 • F6 = F5 + F4= 11 + 10 = 21 • F7 = F6 + F5= 21 + 22 = 43 • F8 = F7 + F6= 43 + 42 = 85 • F9 = F8 + F7= 85 + 86 = 171 • F10 = F9 + F8= 171 + 170 = 341 • F11 = F10 + F9= 341 + 342 = 683 • F12 = F11 + F10= 683 + 682 = 1365 . . .

Computing Values using Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Statement: • Start with a different kind of pair of rabbits, one male and

one female, born on January 1. • Assume all months are of equal length and that rabbits

begin to produce three months after their own birth. • After reaching age of three months, each pair produces

another mixed pairs, one male and other female, and then another mixed pair each month, and no rabbit dies. How many pairs of rabbits will there be after one year?

Answer: Generalization of Fibonacci Sequence! 0, 1, 1, 1, 2, 3, 4, 6, 9, 13, 19, 28, 41, 60, . . .

Another Generalization of Rabbits Problem

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Construction of Mathematical Model

F3 = 1

F4 = 2

F6 = 4

F8 = 9

F1 = 1

F0 = 0

F5 = 3

F2 = 1

F7 = 6

F9 = 13

F10 = 19 Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Total pairs at level k = Total pairs at level k-1 + Total pairs born at level k (1)

• Since Total pairs born at level k = Total pairs at level k-3 (2)

• By (1) and (2) Total pairs at level k = Total pairs at level k-1 + Total pairs at level k-3

• Now let us denote Fk = Total pairs at level k

• This time mathematical model: Fk = Fk-1 + Fk-3

Construction of Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Since Fk = Fk-1 + Fk-3 F0 = 0, F1= F2= 1 • F3 = F2 + F0= 1 + 0 = 1 • F4 = F3 + F1= 1 + 1 = 2 • F5 = F4 + F2= 2 + 1 = 3 • F6 = F5 + F3= 3 + 1 = 4 • F7 = F6 + F4= 4 + 2 = 6 • F8 = F7 + F5= 6 + 3 = 9 • F9 = F8 + F6= 9 + 4 = 13 • F10 = F9 + F7= 13 + 6 = 19 • F11 = F10 + F8= 19 + 9 = 28 • F12 = F11 + F9= 28 + 13 = 41 . . .

Computing Values using Mathematical Model

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

• Recursive mathematical model (one pair, production after three months)

Fk = Fk-1 + Fk-3 • Recursive mathematical model

(two pairs, production after three months) Fk = Fk-1 + 2.Fk-3

• Recursive mathematical model (m pairs, production after three months)

Fk = Fk-1 + m.Fk-3 • Recursive mathematical model

(m pairs, production after n months) Fk = Fk-1 + m.Fk-n

More Generalization

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Fibonacci sequences • Are used in trend analysis • By some pseudorandom number generators • The number of petals is a Fibonacci number. • Many plants show the Fibonacci numbers in the

arrangements of the leaves around the stems. • Seen in arrangement of seeds on flower heads • Consecutive Fibonacci numbers give worst case

behavior when used as inputs in Euclid’s algorithm. • As n approaches infinity, the ratio F(n+1)/F(n)

approaches the golden ratio:  =1.6180339887498948482...

Applications of Fibonacci Sequences

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Fibonacci sequences • The Greeks felt that rectangles whose sides are in

the golden ratio are most pleasing • The Fibonacci number F(n+1) gives the number of

ways for 2 x 1 dominoes to cover a 2 x n checkerboard.

• Sum of the first n Fibonacci numbers is F(n+2)-1. • The shallow diagonals of Pascal’s triangle sum to

Fibonacci numbers. • Except n = 4, if F(n) is prime, then n is prime. • Equivalently, if n not prime, then F(n) is not prime. • gcd( F(n), F(m) ) = F( gcd(n, m) )

Applications of Fibonacci Sequences

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

docsity.com

Docsity is not optimized for the browser you're using. In order to have a better experience please switch to Google Chrome, Firefox, Internet Explorer 9+ or Safari! Download Google Chrome