Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Lecture 4,5 Mathematical Induction and Fibonacci Sequences What is Mathematical Induction? • • • • Mathematical induction is a powerful, yet straightforward method of proving statements whose domain is a subset of the set of integers. Usually, a statement that is proven by induction is based on the set of natural numbers. This statement can often be thought of as a function of a number n, where n = 1, 2, 3,. . . Proof by induction involves three main steps – – – Proving the base of induction Forming the induction hypothesis Proving that the induction hypothesis holds true for all numbers in the domain. mashhoood.webs.com 2 What is Mathematical Induction? Let P(n) be the predicate defined for any positive integers n, and let n0 be a fixed integer. Suppose the following two statements are true 1. P(n0) is true. 2. For any positive integers k, k n0, 3. if P(k) is true then P(k+1)is true. If the above statements are true then the statement: n N, such that n n0, P(n) is also true mashhoood.webs.com 3 Steps in Proving by Induction Claim: P(n) is true for all n Z+, for n n0 1. Basis – Show formula is true when n = n0 2. Inductive hypothesis – Assume formula is true for an arbitrary n = k where, k Z+ and k n0 3. To Prove Claim – Show that formula is then true for k+1 Note: In fact we have to prove 1) P(n0) and 2) P(k) P(k+1) mashhoood.webs.com 4 Proof by Induction Example 1 • Prove that n2 n + 100 n 11 Solution Let P(n) n2 n + 100 n 11 1. P(11) 112 11 + 100 121 111, true 2. Suppose predicate is true for n = k, i.e. P(k) k2 k + 100, true k 11 3. Now it can be proved that P(k+1) (k+1)2 (k+1) + 100, k2 + 2k +1 k +1 + 100 k2 + k 100 (by 1 and 2) Hence P(k) P(K+1) mashhoood.webs.com 5 Validity of Proof Example 1 • Prove that n2 n + 100 n 11 Solution Initially, base case Solution set = {11} By, P(k) P(K+1) P(11) P(12), taking k = 11 Solution set = {11, 12} Similarly, P(12) P(13), taking k = 12 Solution set = {11, 12, 13} And, P(13) P(14), taking k = 13 Solution set = {11, 12, 13, 14} And so on mashhoood.webs.com 6 Another Easy Example Reasoning of Proof Example 2 Use Mathematical Induction to prove that sum of the first n odd positive integers is n2. Proof n • Let P(n) denote the proposition that (2i 1) n 2 i 1 2 • Basis step : P(1) is true , since 1 = 1 • Inductive step : Let P(k) is true for a positive integer k, i.e., 1+3+5+…+(2k-1) = k2 • Note that: 1+3+5+…+(2k-1)+(2k+1) = k2+2k+1= (k+1)2 ∴ P(k+1) true, by induction, P(n) is true for all n Z+ n n Another Proof (2i 1) 2 i n n(n 1) n n 2 i 1 i 1 mashhoood.webs.com 7 Reasoning of Proof Example 3 • Use mathematical Induction to prove that n < 2n for all n Z+ Proof • Let P(n) be the proposition that n < 2n • Basis step : P(1) is true since 1 < 21 . • Inductive step : Assume that P(n) is true for a positive integer n = k, i.e., k < 2k. • Now consider for P(k+1) : Since, k + 1 < 2k + 1 2k + 2k = 2.2k = 2k + 1 ∴ P(k+1) is true. It proves that P(n) is true for all n Z+. mashhoood.webs.com 8 Example 4: Harmonic Numbers The harmonic numbers Hk, k = 1, 2, 3, …, are defined by H 1 1 1 ... 1 k 2 3 k n H 2n 1 Use mathematical induction to show that 2 whenever n is a nonnegative integer. Proof Let P(n) be the proposition that H 2n 1 n / 2 Basis step : P(0) is true, since, H 0 H1 1 1 0 / 2 1 2 Inductive step Assume that P(k) is true for some k, mashhoood.webs.com H 2k 1 k / 2 9 Example 4: Harmonic Numbers Now consider H 2k 1 1 1 1 1 1 1 1 k k k k 1 2 3 2 2 1 2 2 2 2k 2k 1 1 1 H 2k k k k 1 2 1 2 2 2 k 1 1 1 (1 ) k k k 1 2 2 1 2 2 2 k 1 1 1 (1 ) k k k k k 2 2 2 2 2 2 2k k 2k k 1 k 1 (1 ) k 1 k 1 2 2 2 2 2 2 ∴P(k+1) is true. Hence the statement is true for all n Z+. mashhoood.webs.com 10 Fibonacci Sequences Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Today Covered In this lecture we will cover the following: • Fibonacci Problem and its Sequence • Construction of Mathematical Model • Recursive Algorithms • Generalizations of Rabbits Problem and Constructing its Mathematical Models • Applications of Fibonacci Sequences mashhoood.webs.com 12 Fibonacci Sequence • 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. • 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. mashhoood.webs.com 13 Fibonacci’s Problem 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, . . . mashhoood.webs.com 14 Construction of Mathematical Model F0 = 0 F1 = 1 end of month 1 end of month 2 F2 = 1 end of month 3 F3 = 2 F4 = 3 end of month 4 end of month 5 F5 = 5 end of month 6 F6 = 8 end of month 7 ... ... F7 = 13 mashhoood.webs.com ... end of month 12 15 Construction of Mathematical Model • 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 mashhoood.webs.com 16 Computing Values using Mathematical Model Since Fk = Fk-1 + Fk-2 • F2 = F1 + F0= 1 + 0 = 1 • F 3 = F 2 + F 1= 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 . . . mashhoood.webs.com F0 = 0, F1= 1 17 Explicit Formula Computing Fibonacci Numbers Theorem: The fibonacci sequence F0,F1, F2,…. Satisfies the recurrence relation Fk Fk 1 Fk 2 k 2 with initial condition F0 F1 1 Find the explicit formula for this sequence. Solution: The given fibonacci sequence Fk Fk 1 Fk 2 Let tk is solution to this, then characteristic equation t 2 t 1 0 mashhoood.webs.com 18 Fibonacci Sequence t1 1 1 4 2 1 5 1 5 , t2 2 2 t For some real C and D fibonacci sequence satisfies the relation n 1 5 1 5 D Fn C 2 2 n0 0 1 5 1 5 F0 C D 2 2 F0 C D n n0 0 C D 0 1 F0 0 mashhoood.webs.com 19 Fibonacci Sequence Now n 1 1 5 1 5 D F1 C 2 2 1 5 1 5 C D 1 2 2 2 F1 1 Solving 1 and 2 simultaneo usly we get 1 1 C ,D 5 5 Hence n 1 1 5 1 1 5 Fn 5 2 5 2 5 mashhoood.webs.com Dr Nazir A. Zafar n 20 Advanced Algorithms Analysis and Design Fibonacci Sequence After simplifying we get n 1 1 5 1 1 5 Fn 5 2 5 2 n which is called the explicit formula for the Fibonacci sequence recurrence relation. 1 5 1 5 and then Let 2 2 1 n 1 n Fn 5 5 mashhoood.webs.com 21 Verification of the Explicit Formula Example: Compute F3 1 5 1 5 1 n 1 n and then Since Fn where 2 5 5 2 3 3 1 1 5 1 1 5 F3 5 2 5 2 1 1 3.12. 5 3.1.5 5 5 1 1 3.12. 5 3.1.5 5 5 Now, F3 8 8 5 5 1 1 F3 1 3.1. 5 3.1.5 5 5 1 3.1. 5 3.1.5 5 5 8. 5 8. 5 1 F3 1 3.1. 5 3.1.5 5 5 1 3.1. 5 3.1.5 5 5 2 8. 5 mashhoood.webs.com 22 Recursive Algorithm Computing Fibonacci Numbers Fibo-R(n) if n = 0 then 0 Terminating conditions if n = 1 then 1 else Fibo-R(n-1) + Fibo-R(n-2) Recursive calls mashhoood.webs.com 23 Running Time of Recursive Fibonacci Algorithm • Least Cost: To find an asymptotic bound of computational cost of this algorithm. if n 2 1 T ( n) T (n 1) T (n 2) n 2 mashhoood.webs.com 24 Drawback in Recursive Algorithms Recursion Tree F(n) F(n-1) F(n-2) F(0) F(n-2) F(n-3) F(1) F(n-3) F(1) mashhoood.webs.com F(n-4) F(0) 25 Generalization of Rabbits Problem 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, . . . mashhoood.webs.com 26 Construction of Mathematical Model F0 = 0 F1 = 1 F2 = 1 F3 = 3 F4 = 5 F5 = 11 F6 = 21 mashhoood.webs.com 27 Construction of Mathematical Model • 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 mashhoood.webs.com 28 Generalization • 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 mashhoood.webs.com 29 Computing Values using Mathematical Model 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 . . . mashhoood.webs.com 30 Another Generalization of Rabbits Problem 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, . . . mashhoood.webs.com 31 Construction of Mathematical Model F0 = 0 F1 = 1 F2 = 1 F3 = 1 F4 = 2 F5 = 3 F6 = 4 F7 = 6 F8 = 9 F9 = 13 mashhoood.webs.com F10 = 19 32 Construction of Mathematical Model • Total pairs at level k = Total pairs at level k-1 + Total pairs born at level k • Since Total pairs born at level k = Total pairs at level k-3 • 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 mashhoood.webs.com (1) (2) 33 Computing Values using Mathematical Model Since Fk = Fk-1 + Fk-3 • F3 = F2 + F0= 1 + 0 = 1 • F 4 = F 3 + F 1= 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 . . . mashhoood.webs.com F0 = 0, F1= F2= 1 34 More Generalization • 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 mashhoood.webs.com 35 Applications of Fibonacci Sequences Fibonacci sequences • Are used in trend analysis • By some pseudorandom number generators • 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. mashhoood.webs.com 36