Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.

Slides:



Advertisements
Similar presentations
Biography ( ) Fibonacci is a short for the Latin "filius Bonacci" which means "the son of Bonacci" but his full name was Leonardo of Pisa, or Leonardo.
Advertisements

22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Recursive Definitions and Structural Induction
Fibonacci Leonardo Pisano. The start of a genius We note that in a time interval of one thousand years, i.e. from 400 until 1400, then existed only one.
Induction and Recursion. Odd Powers Are Odd Fact: If m is odd and n is odd, then nm is odd. Proposition: for an odd number m, m k is odd for all non-negative.
Fibonacci Sequences Susan Leggett, Zuzana Zvarova, Sara Campbell
Lecture 3, Tuesday, Aug. 29. Chapter 2: Single species growth models, continued 2.1. Linear difference equations, Fibonacci number and golden ratio. Required.
The Sequence of Fibonacci Numbers and How They Relate to Nature November 30, 2004 Allison Trask.
FIBONACCI NUMBERS 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, ,
Induction and recursion
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Analysis of Recursive Algorithms October 29, 2014
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
Slide 5-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.
Induction and recursion
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Analysis of Algorithms
The Golden Ratio and Fibonacci Numbers in Nature
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Chapter 4: Induction and Recursion
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
1 Recurrences Algorithms Jay Urbain, PhD Credits: Discrete Mathematics and Its Applications, by Kenneth Rosen The Design and Analysis of.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, = 3, so 3 is an odd positive integer.
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
Sequences and Summations
Aim: Arithmetic Sequence Course: Alg. 2 & Trig. Do Now: Aim: What is an arithmetic sequence and series? Find the next three numbers in the sequence 1,
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Chapter 5 With Question/Answer Animations. Section 5.1.
Lecture 4,5 Mathematical Induction and Fibonacci Sequences.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Fermat’s Little Theorem Fibonacci Numbers Shirley Moore CS4390/5390 Fall September 10,
Fibonacci Sequences and the Golden Ratio Carl Wozniak Northern Michigan University.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
COMPSCI 102 Introduction to Discrete Mathematics.
Asymptotics and Recurrence Equations Prepared by John Reif, Ph.D. Analysis of Algorithms.
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Advanced Algorithms Analysis and Design
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.
“Toy” Model: Fibonacci The Fibonacci sequence first appears in the book Liber Abaci (1202) by Leonardo of Pisa, known as Fibonacci.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 2.
7.4 Exploring recursive sequences fibonacci
A Number You Can Call Your Own
Modeling with Recurrence Relations
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Induction: One Step At A Time
Advanced Algorithms Analysis and Design
CS2210:0001Discrete Structures Induction and Recursion
The Golden Ratio and Fibonacci Numbers in Nature
Chapter 5 Induction and Recursion
Ch 4: Recurrences Ming-Te Chi
Applied Discrete Mathematics Week 7: Computation
1A Recursively Defined Functions
CSC 380: Design and Analysis of Algorithms
Algorithms Recurrences.
Mathematical Induction
Induction: One Step At A Time
Presentation transcript:

Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar

Lecture No. 6 Fibonacci Sequences (Natural Models) Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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

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

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

Construction of Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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 F k = Total pairs at level k Now our recursive mathematical model will become F k = F k-1 + F k-2 Construction of Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Since F k = F k-1 + F k-2 F 0 = 0, F 1 = 1 F 2 = F 1 + F 0 = = 1 F 3 = F 2 + F 1 = = 2 F 4 = F 3 + F 2 = = 3 F 5 = F 4 + F 3 = = 5 F 6 = F 5 + F 4 = = 8 F 7 = F 6 + F 5 = = 13 F 8 = F 7 + F 6 = = 21 F 9 = F 8 + F 7 = = 34 F 10 = F 9 + F 8 = = 55 F 11 = F 10 + F 9 = = 89 F 12 = F 11 + F 10 = = Computing Values using Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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 Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Fibonacci Sequence For some real C and D fibonacci sequence satisfies the relation Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Fibonacci Sequence Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

After simplifying we get which is called the explicit formula for the Fibonacci sequence recurrence relation. Fibonacci Sequence Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Example: Compute F 3 Verification of the Explicit Formula Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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

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 Running Time of Recursive Fibonacci Algorithm Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Construction of Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Guess that F n+1 is the least cost to solve this recurrence. Why this guess?  n  0, T(n)  F n+1 then F n+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 F 1 = 1, hence T(0)  F 1 For n = 1, T(1) = 1 and F 2 = 1, hence T(1)  F 2 Running Time of Recursive Fibonacci Algorithm Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Inductive Hypothesis Let us suppose that statement is true some k  1 T(k)  F k+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)  F k+1 + F k = F k+2 Assumption T(k + 1)  F k+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  (F n+1 ). Running Time of Recursive Fibonacci Algorithm Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Now we have proved that T(n)  F n+1, n  0(1) We already proved in solution to recursive relation that It can be easily verified that F n   n /5  (3/2) n From the equations (1) and (2), T(n)  F n+1  F n  (3/2) n Hence we can conclude that r unning time of our recursive Fibonacci Algorithm is: T(n) =  (3/2) n Running Time of Recursive Fibonacci Algorithm Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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 Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Golden Ratio Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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-4) F(1)F(0) Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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

Construction of Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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 x Total pairs at level k-2 Now let us denote F k = Total pairs at level k Our recursive mathematical model: F k = F k F k-2 General Model (m pairs production): F k = F k-1 + m.F k-2 Construction of Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Recursive mathematical model (one pair production) F k = F k-1 + F k-2 Recursive mathematical model (two pairs production) F k = F k F k-2 Recursive mathematical model (m pairs production) F k = F k-1 + m.F k-2 Generalization Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Since F k = F k F k-2 F 0 = 0, F 1 = 1 F 2 = F F 0 = = 1 F 3 = F F 1 = = 3 F 4 = F F 2 = = 5 F 5 = F F 3 = = 11 F 6 = F 5 + F 4 = = 21 F 7 = F 6 + F 5 = = 43 F 8 = F 7 + F 6 = = 85 F 9 = F 8 + F 7 = = 171 F 10 = F 9 + F 8 = = 341 F 11 = F 10 + F 9 = = 683 F 12 = F 11 + F 10 = = Computing Values using Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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

Construction of Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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 F k = Total pairs at level k This time mathematical model:F k = F k-1 + F k-3 Construction of Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Since F k = F k-1 + F k-3 F 0 = 0, F 1 = F 2 = 1 F 3 = F 2 + F 0 = = 1 F 4 = F 3 + F 1 = = 2 F 5 = F 4 + F 2 = = 3 F 6 = F 5 + F 3 = = 4 F 7 = F 6 + F 4 = = 6 F 8 = F 7 + F 5 = = 9 F 9 = F 8 + F 6 = = 13 F 10 = F 9 + F 7 = = 19 F 11 = F 10 + F 8 = = 28 F 12 = F 11 + F 9 = = Computing Values using Mathematical Model Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

Recursive mathematical model (one pair, production after three months) F k = F k-1 + F k-3 Recursive mathematical model (two pairs, production after three months) F k = F k F k-3 Recursive mathematical model (m pairs, production after three months) F k = F k-1 + m.F k-3 Recursive mathematical model (m pairs, production after n months) F k = F k-1 + m.F k-n More Generalization Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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:  = Applications of Fibonacci Sequences Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

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