<<

Lecture 9: Recurrence Relations

Matthew Fricke

Definition

Examples

Guess and Check Lecture 9: Recurrence Relations Binary Search

Characteristic Equation Matthew Fricke Method

The Fibonacci Sequence Golden Ratio July 15, 2013 Gambler’s Ruin Lecture 9: Recurrence Relations This Lecture Matthew Fricke

Definition 1 Definition

Examples

Guess and 2 Examples Check Binary Search 3 Guess and Check Characteristic Equation Method 4 Binary Search The Fibonacci Sequence

Golden Ratio 5 Characteristic Equation Method

Gambler’s Ruin 6 The Fibonacci Sequence

7 Golden Ratio

8 Gambler’s Ruin • Recurrence relations are closely tied to differential equations because they are both self referential. • A differential equation relates a function to its own derivative. • The discrete version of a differential equation is a difference equation. • Sometimes people call recurrence relations difference equations but really difference equations are just a type of recurrence relation. • Some of the techniques for solving recurrence relations are almost the same as those used to solve differential equations.

Lecture 9: Recurrence Relations What are Recurrence Relations? Matthew Fricke • A recurrence relation is an equation that defines a value in Definition a sequence using previous values in the sequence. Examples

Guess and Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • A differential equation relates a function to its own derivative. • The discrete version of a differential equation is a difference equation. • Sometimes people call recurrence relations difference equations but really difference equations are just a type of recurrence relation. • Some of the techniques for solving recurrence relations are almost the same as those used to solve differential equations.

Lecture 9: Recurrence Relations What are Recurrence Relations? Matthew Fricke • A recurrence relation is an equation that defines a value in Definition a sequence using previous values in the sequence. Examples

Guess and • Recurrence relations are closely tied to differential Check equations because they are both self referential. Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • The discrete version of a differential equation is a difference equation. • Sometimes people call recurrence relations difference equations but really difference equations are just a type of recurrence relation. • Some of the techniques for solving recurrence relations are almost the same as those used to solve differential equations.

Lecture 9: Recurrence Relations What are Recurrence Relations? Matthew Fricke • A recurrence relation is an equation that defines a value in Definition a sequence using previous values in the sequence. Examples

Guess and • Recurrence relations are closely tied to differential Check equations because they are both self referential. Binary Search

Characteristic • A differential equation relates a function to its own Equation Method derivative.

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Sometimes people call recurrence relations difference equations but really difference equations are just a type of recurrence relation. • Some of the techniques for solving recurrence relations are almost the same as those used to solve differential equations.

Lecture 9: Recurrence Relations What are Recurrence Relations? Matthew Fricke • A recurrence relation is an equation that defines a value in Definition a sequence using previous values in the sequence. Examples

Guess and • Recurrence relations are closely tied to differential Check equations because they are both self referential. Binary Search

Characteristic • A differential equation relates a function to its own Equation Method derivative. The Fibonacci • The discrete version of a differential equation is a Sequence difference equation. Golden Ratio

Gambler’s Ruin • Some of the techniques for solving recurrence relations are almost the same as those used to solve differential equations.

Lecture 9: Recurrence Relations What are Recurrence Relations? Matthew Fricke • A recurrence relation is an equation that defines a value in Definition a sequence using previous values in the sequence. Examples

Guess and • Recurrence relations are closely tied to differential Check equations because they are both self referential. Binary Search

Characteristic • A differential equation relates a function to its own Equation Method derivative. The Fibonacci • The discrete version of a differential equation is a Sequence difference equation. Golden Ratio

Gambler’s • Sometimes people call recurrence relations difference Ruin equations but really difference equations are just a type of recurrence relation. Lecture 9: Recurrence Relations What are Recurrence Relations? Matthew Fricke • A recurrence relation is an equation that defines a value in Definition a sequence using previous values in the sequence. Examples

Guess and • Recurrence relations are closely tied to differential Check equations because they are both self referential. Binary Search

Characteristic • A differential equation relates a function to its own Equation Method derivative. The Fibonacci • The discrete version of a differential equation is a Sequence difference equation. Golden Ratio

Gambler’s • Sometimes people call recurrence relations difference Ruin equations but really difference equations are just a type of recurrence relation. • Some of the techniques for solving recurrence relations are almost the same as those used to solve differential equations. Lecture 9: Recurrence Relations Examples of Recursion Relations Matthew Fricke

Definition Examples Towers of Hanoi T0 = 0 Guess and Check Tn = 2Tn−1 + 1

Binary Search

Characteristic Equation Fibonacci Sequence F0 = 0 Method F = 1 The Fibonacci 1 Sequence Fn = Fn−1 + Fn−2 Golden Ratio

Gambler’s Ruin Compound Interest

Stirling Numbers • We solved the problem by figuring out a general statement characterizing the amount of work needed to move one disk from one peg to another: 2(n − 1) + 1 where n is the number of disks. • Then we wrote out the sequence values for T0, T1, T2, T3, T4 ... = 0, 1, 3, 7, 15 ... • Guessed that the formula was 2n − 1 • ... and proved it with mathematical induction.

Lecture 9: Recurrence Relations Towers of Hanoi Matthew Fricke

Definition

Examples • Recall that the recurrence Tn represents the amount of Guess and Check work needed to solve the problem.

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Then we wrote out the sequence values for T0, T1, T2, T3, T4 ... = 0, 1, 3, 7, 15 ... • Guessed that the formula was 2n − 1 • ... and proved it with mathematical induction.

Lecture 9: Recurrence Relations Towers of Hanoi Matthew Fricke

Definition

Examples • Recall that the recurrence Tn represents the amount of Guess and Check work needed to solve the problem. Binary Search • We solved the problem by figuring out a general statement Characteristic Equation characterizing the amount of work needed to move one Method disk from one peg to another: 2(n − 1) + 1 where n is the The Fibonacci Sequence number of disks.

Golden Ratio

Gambler’s Ruin • Guessed that the formula was 2n − 1 • ... and proved it with mathematical induction.

Lecture 9: Recurrence Relations Towers of Hanoi Matthew Fricke

Definition

Examples • Recall that the recurrence Tn represents the amount of Guess and Check work needed to solve the problem. Binary Search • We solved the problem by figuring out a general statement Characteristic Equation characterizing the amount of work needed to move one Method disk from one peg to another: 2(n − 1) + 1 where n is the The Fibonacci Sequence number of disks. Golden Ratio • Then we wrote out the sequence values for Gambler’s T , T , T , T , T ... = 0, 1, 3, 7, 15 ... Ruin 0 1 2 3 4 • ... and proved it with mathematical induction.

Lecture 9: Recurrence Relations Towers of Hanoi Matthew Fricke

Definition

Examples • Recall that the recurrence Tn represents the amount of Guess and Check work needed to solve the problem. Binary Search • We solved the problem by figuring out a general statement Characteristic Equation characterizing the amount of work needed to move one Method disk from one peg to another: 2(n − 1) + 1 where n is the The Fibonacci Sequence number of disks. Golden Ratio • Then we wrote out the sequence values for Gambler’s T , T , T , T , T ... = 0, 1, 3, 7, 15 ... Ruin 0 1 2 3 4 • Guessed that the formula was 2n − 1 Lecture 9: Recurrence Relations Towers of Hanoi Matthew Fricke

Definition

Examples • Recall that the recurrence Tn represents the amount of Guess and Check work needed to solve the problem. Binary Search • We solved the problem by figuring out a general statement Characteristic Equation characterizing the amount of work needed to move one Method disk from one peg to another: 2(n − 1) + 1 where n is the The Fibonacci Sequence number of disks. Golden Ratio • Then we wrote out the sequence values for Gambler’s T , T , T , T , T ... = 0, 1, 3, 7, 15 ... Ruin 0 1 2 3 4 • Guessed that the formula was 2n − 1 • ... and proved it with mathematical induction. • then analyse the amount of work needed to search using recurrence relations. • Given a sorted array of how might we determine if a particular is in the array?

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check

Binary Search • We are going to come up with an to solve a

Characteristic search problem. Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Given a sorted array of integers how might we determine if a particular integer is in the array?

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check

Binary Search • We are going to come up with an algorithm to solve a

Characteristic search problem. Equation Method • then analyse the amount of work needed to search using The Fibonacci recurrence relations. Sequence

Golden Ratio

Gambler’s Ruin Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check

Binary Search • We are going to come up with an algorithm to solve a

Characteristic search problem. Equation Method • then analyse the amount of work needed to search using The Fibonacci recurrence relations. Sequence

Golden Ratio • Given a sorted array of integers how might we determine if

Gambler’s a particular integer is in the array? Ruin Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition Examples 1: function BinSearch(key, array, start, end) Guess and Check 2: if end ≤ start then

Binary Search 3: return FALSE

Characteristic 4: else Equation end+start Method 5: mid ← 2 The Fibonacci 6: if key = array[mid] then Sequence 7: return TRUE Golden Ratio 8: else if key ≤ array[mid] then Gambler’s Ruin 9: return BinSearch(key, array, start, mid) 10: else if key > array[mid] then 11: return BinSearch(key, array, mid, end) • We are thinking about the work done in the worst case (we might find the key on the first try). • Typically “work” means operations or memory accesses. • Notice that due to Line 5 in the algorithm each recursive call only needs to work on half the array that the previous call worked on. n • So we guess that T (n) = T ( 2 ) + 1, n = the size of the array. • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Let’s define a recurrence relation T (n) (T for time) that

Guess and describes the amount of work to be done by BinarySearch. Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Typically “work” means operations or memory accesses. • Notice that due to Line 5 in the algorithm each recursive call only needs to work on half the array that the previous call worked on. n • So we guess that T (n) = T ( 2 ) + 1, n = the size of the array. • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Let’s define a recurrence relation T (n) (T for time) that

Guess and describes the amount of work to be done by BinarySearch. Check • We are thinking about the work done in the worst case Binary Search

Characteristic (we might find the key on the first try). Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Notice that due to Line 5 in the algorithm each recursive call only needs to work on half the array that the previous call worked on. n • So we guess that T (n) = T ( 2 ) + 1, n = the size of the array. • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Let’s define a recurrence relation T (n) (T for time) that

Guess and describes the amount of work to be done by BinarySearch. Check • We are thinking about the work done in the worst case Binary Search

Characteristic (we might find the key on the first try). Equation Method • Typically “work” means operations or memory accesses.

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin n • So we guess that T (n) = T ( 2 ) + 1, n = the size of the array. • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Let’s define a recurrence relation T (n) (T for time) that

Guess and describes the amount of work to be done by BinarySearch. Check • We are thinking about the work done in the worst case Binary Search

Characteristic (we might find the key on the first try). Equation Method • Typically “work” means operations or memory accesses. The Fibonacci • Sequence Notice that due to Line 5 in the algorithm each recursive

Golden Ratio call only needs to work on half the array that the previous

Gambler’s call worked on. Ruin • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Let’s define a recurrence relation T (n) (T for time) that

Guess and describes the amount of work to be done by BinarySearch. Check • We are thinking about the work done in the worst case Binary Search

Characteristic (we might find the key on the first try). Equation Method • Typically “work” means operations or memory accesses. The Fibonacci • Sequence Notice that due to Line 5 in the algorithm each recursive

Golden Ratio call only needs to work on half the array that the previous

Gambler’s call worked on. Ruin n • So we guess that T (n) = T ( 2 ) + 1, n = the size of the array. Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Let’s define a recurrence relation T (n) (T for time) that

Guess and describes the amount of work to be done by BinarySearch. Check • We are thinking about the work done in the worst case Binary Search

Characteristic (we might find the key on the first try). Equation Method • Typically “work” means operations or memory accesses. The Fibonacci • Sequence Notice that due to Line 5 in the algorithm each recursive

Golden Ratio call only needs to work on half the array that the previous

Gambler’s call worked on. Ruin n • So we guess that T (n) = T ( 2 ) + 1, n = the size of the array. • Base case: T (2) = 1 • Intuitively if we have a sequence that doubles at each step we get: 1, 2, 4, 8, 16 .... • We recognize this as 2n which is an exponential function. • If we halve the values at each step ... 16, 8, 4, 2, 1 we are doing the inverse. • The inverse of an exponential function is the logarithmic function.

• Therefore we guess that that T (n) = log2(n) • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • We would like to put the recurrence in closed form. That

Guess and is we would like to solve the recurrence. Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • We recognize this as 2n which is an exponential function. • If we halve the values at each step ... 16, 8, 4, 2, 1 we are doing the inverse. • The inverse of an exponential function is the logarithmic function.

• Therefore we guess that that T (n) = log2(n) • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • We would like to put the recurrence in closed form. That

Guess and is we would like to solve the recurrence. Check • Intuitively if we have a sequence that doubles at each step Binary Search we get: 1, 2, 4, 8, 16 .... Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • If we halve the values at each step ... 16, 8, 4, 2, 1 we are doing the inverse. • The inverse of an exponential function is the logarithmic function.

• Therefore we guess that that T (n) = log2(n) • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • We would like to put the recurrence in closed form. That

Guess and is we would like to solve the recurrence. Check • Intuitively if we have a sequence that doubles at each step Binary Search we get: 1, 2, 4, 8, 16 .... Characteristic Equation n Method • We recognize this as 2 which is an exponential function.

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • The inverse of an exponential function is the logarithmic function.

• Therefore we guess that that T (n) = log2(n) • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • We would like to put the recurrence in closed form. That

Guess and is we would like to solve the recurrence. Check • Intuitively if we have a sequence that doubles at each step Binary Search we get: 1, 2, 4, 8, 16 .... Characteristic Equation n Method • We recognize this as 2 which is an exponential function. The Fibonacci • If we halve the values at each step ... 16, 8, 4, 2, 1 we are Sequence

Golden Ratio doing the inverse.

Gambler’s Ruin • Therefore we guess that that T (n) = log2(n) • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • We would like to put the recurrence in closed form. That

Guess and is we would like to solve the recurrence. Check • Intuitively if we have a sequence that doubles at each step Binary Search we get: 1, 2, 4, 8, 16 .... Characteristic Equation n Method • We recognize this as 2 which is an exponential function. The Fibonacci • If we halve the values at each step ... 16, 8, 4, 2, 1 we are Sequence

Golden Ratio doing the inverse. Gambler’s • The inverse of an exponential function is the logarithmic Ruin function. • Base case: T (2) = 1

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • We would like to put the recurrence in closed form. That

Guess and is we would like to solve the recurrence. Check • Intuitively if we have a sequence that doubles at each step Binary Search we get: 1, 2, 4, 8, 16 .... Characteristic Equation n Method • We recognize this as 2 which is an exponential function. The Fibonacci • If we halve the values at each step ... 16, 8, 4, 2, 1 we are Sequence

Golden Ratio doing the inverse. Gambler’s • The inverse of an exponential function is the logarithmic Ruin function.

• Therefore we guess that that T (n) = log2(n) Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • We would like to put the recurrence in closed form. That

Guess and is we would like to solve the recurrence. Check • Intuitively if we have a sequence that doubles at each step Binary Search we get: 1, 2, 4, 8, 16 .... Characteristic Equation n Method • We recognize this as 2 which is an exponential function. The Fibonacci • If we halve the values at each step ... 16, 8, 4, 2, 1 we are Sequence

Golden Ratio doing the inverse. Gambler’s • The inverse of an exponential function is the logarithmic Ruin function.

• Therefore we guess that that T (n) = log2(n) • Base case: T (2) = 1 • Proof by strong induction:

• Base case n = 2: log2(2 · 2) = 1, QED for Base Case j • Inductive Step: ∀j < k, T (j) = T ( 2 ) + 1 = log2(j) =⇒ k T (k) = T ( 2 ) + 1 = log2(k)

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • The next step is to try and prove our guess was right with Binary Search mathematical induction. Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Base case n = 2: log2(2 · 2) = 1, QED for Base Case j • Inductive Step: ∀j < k, T (j) = T ( 2 ) + 1 = log2(j) =⇒ k T (k) = T ( 2 ) + 1 = log2(k)

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • The next step is to try and prove our guess was right with Binary Search mathematical induction. Characteristic Equation Method • Proof by strong induction:

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin j • Inductive Step: ∀j < k, T (j) = T ( 2 ) + 1 = log2(j) =⇒ k T (k) = T ( 2 ) + 1 = log2(k)

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • The next step is to try and prove our guess was right with Binary Search mathematical induction. Characteristic Equation Method • Proof by strong induction: The Fibonacci • Base case n = 2: log (2 · 2) = 1, QED for Base Case Sequence 2

Golden Ratio

Gambler’s Ruin Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • The next step is to try and prove our guess was right with Binary Search mathematical induction. Characteristic Equation Method • Proof by strong induction: The Fibonacci • Base case n = 2: log (2 · 2) = 1, QED for Base Case Sequence 2 j Golden Ratio • Inductive Step: ∀j < k, T (j) = T ( 2 ) + 1 = log2(j) =⇒ k Gambler’s T (k) = T ( ) + 1 = log2(k) Ruin 2 k • T (k) = T ( 2 ) + 1 this is a premise. k k k • 2 < k =⇒ T ( 2 ) = log2( 2 ) induction hypothesis. k k • T ( 2 ) = log2 2 = log2 k − log2 2 = log2 k − 1 by log rules. k • T (k) = T ( 2 ) + 1 = {log2(k) − 1} + 1 by . • T (k) = log2(k) by simplification of −1 + 1. QED

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • Proof of the inductive step: Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin k k k • 2 < k =⇒ T ( 2 ) = log2( 2 ) induction hypothesis. k k • T ( 2 ) = log2 2 = log2 k − log2 2 = log2 k − 1 by log rules. k • T (k) = T ( 2 ) + 1 = {log2(k) − 1} + 1 by substitution. • T (k) = log2(k) by simplification of −1 + 1. QED

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • Proof of the inductive step: Binary Search • T (k) = T ( k ) + 1 this is a premise. Characteristic 2 Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin k k • T ( 2 ) = log2 2 = log2 k − log2 2 = log2 k − 1 by log rules. k • T (k) = T ( 2 ) + 1 = {log2(k) − 1} + 1 by substitution. • T (k) = log2(k) by simplification of −1 + 1. QED

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • Proof of the inductive step: Binary Search • T (k) = T ( k ) + 1 this is a premise. Characteristic 2 Equation k k k Method • 2 < k =⇒ T ( 2 ) = log2( 2 ) induction hypothesis. The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin k • T (k) = T ( 2 ) + 1 = {log2(k) − 1} + 1 by substitution. • T (k) = log2(k) by simplification of −1 + 1. QED

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • Proof of the inductive step: Binary Search • T (k) = T ( k ) + 1 this is a premise. Characteristic 2 Equation k k k Method • 2 < k =⇒ T ( 2 ) = log2( 2 ) induction hypothesis. The Fibonacci • k k Sequence T ( 2 ) = log2 2 = log2 k − log2 2 = log2 k − 1 by log rules. Golden Ratio

Gambler’s Ruin • T (k) = log2(k) by simplification of −1 + 1. QED

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • Proof of the inductive step: Binary Search • T (k) = T ( k ) + 1 this is a premise. Characteristic 2 Equation k k k Method • 2 < k =⇒ T ( 2 ) = log2( 2 ) induction hypothesis. The Fibonacci • k k Sequence T ( 2 ) = log2 2 = log2 k − log2 2 = log2 k − 1 by log rules. Golden Ratio k • T (k) = T ( 2 ) + 1 = {log2(k) − 1} + 1 by substitution. Gambler’s Ruin Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples

Guess and Check • Proof of the inductive step: Binary Search • T (k) = T ( k ) + 1 this is a premise. Characteristic 2 Equation k k k Method • 2 < k =⇒ T ( 2 ) = log2( 2 ) induction hypothesis. The Fibonacci • k k Sequence T ( 2 ) = log2 2 = log2 k − log2 2 = log2 k − 1 by log rules. Golden Ratio k • T (k) = T ( 2 ) + 1 = {log2(k) − 1} + 1 by substitution. Gambler’s Ruin • T (k) = log2(k) by simplification of −1 + 1. QED • The progression of thought for this proof is:

• Assume what we want is true. Then T (k) = log2(k)

• We want to make T (k) = T (k/2) + 1 = log2(x) • We have that it is true for everything less than k by strong induction.

• So solve for x : log2(x) = log2(k) − 1 =⇒ log2(x) − log2(2) =⇒ log2(x) = log2(k/2) • ∴ x = k/2 Since k/2 is less than k we can use proof by strong induction.

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Proofs are often presented in the opposite order to which

Guess and they were developed. Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Assume what we want is true. Then T (k) = log2(k)

• We want to make T (k) = T (k/2) + 1 = log2(x) • We have that it is true for everything less than k by strong induction.

• So solve for x : log2(x) = log2(k) − 1 =⇒ log2(x) − log2(2) =⇒ log2(x) = log2(k/2) • ∴ x = k/2 Since k/2 is less than k we can use proof by strong induction.

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Proofs are often presented in the opposite order to which

Guess and they were developed. Check • The progression of thought for this proof is: Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • We want to make T (k) = T (k/2) + 1 = log2(x) • We have that it is true for everything less than k by strong induction.

• So solve for x : log2(x) = log2(k) − 1 =⇒ log2(x) − log2(2) =⇒ log2(x) = log2(k/2) • ∴ x = k/2 Since k/2 is less than k we can use proof by strong induction.

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Proofs are often presented in the opposite order to which

Guess and they were developed. Check • The progression of thought for this proof is: Binary Search Characteristic • Assume what we want is true. Then T (k) = log2(k) Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • We have that it is true for everything less than k by strong induction.

• So solve for x : log2(x) = log2(k) − 1 =⇒ log2(x) − log2(2) =⇒ log2(x) = log2(k/2) • ∴ x = k/2 Since k/2 is less than k we can use proof by strong induction.

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Proofs are often presented in the opposite order to which

Guess and they were developed. Check • The progression of thought for this proof is: Binary Search Characteristic • Assume what we want is true. Then T (k) = log2(k) Equation Method • We want to make T (k) = T (k/2) + 1 = log2(x) The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • So solve for x : log2(x) = log2(k) − 1 =⇒ log2(x) − log2(2) =⇒ log2(x) = log2(k/2) • ∴ x = k/2 Since k/2 is less than k we can use proof by strong induction.

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Proofs are often presented in the opposite order to which

Guess and they were developed. Check • The progression of thought for this proof is: Binary Search Characteristic • Assume what we want is true. Then T (k) = log2(k) Equation Method • We want to make T (k) = T (k/2) + 1 = log2(x) The Fibonacci Sequence • We have that it is true for everything less than k by strong

Golden Ratio induction.

Gambler’s Ruin • ∴ x = k/2 Since k/2 is less than k we can use proof by strong induction.

Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Proofs are often presented in the opposite order to which

Guess and they were developed. Check • The progression of thought for this proof is: Binary Search Characteristic • Assume what we want is true. Then T (k) = log2(k) Equation Method • We want to make T (k) = T (k/2) + 1 = log2(x) The Fibonacci Sequence • We have that it is true for everything less than k by strong

Golden Ratio induction. Gambler’s • Ruin So solve for x : log2(x) = log2(k) − 1 =⇒ log2(x) − log2(2) =⇒ log2(x) = log2(k/2) Lecture 9: Recurrence Relations Binary Search Example Matthew Fricke

Definition

Examples • Proofs are often presented in the opposite order to which

Guess and they were developed. Check • The progression of thought for this proof is: Binary Search Characteristic • Assume what we want is true. Then T (k) = log2(k) Equation Method • We want to make T (k) = T (k/2) + 1 = log2(x) The Fibonacci Sequence • We have that it is true for everything less than k by strong

Golden Ratio induction. Gambler’s • Ruin So solve for x : log2(x) = log2(k) − 1 =⇒ log2(x) − log2(2) =⇒ log2(x) = log2(k/2) • ∴ x = k/2 Since k/2 is less than k we can use proof by strong induction. • More analytical methods include The Master Method, Recursion Trees, and Annihilators. • We will learn a method using the Characteristic Equation of a recurrence. • (The Characteristic Equation comes from Linear Algebra) • The method works on second-order linear recurrence relations with constant coefficients. Annihilators generalize this method to any order. • Second order recurrence: refers to two previous values of the recurrence, e.g. Tn = Tn−1 + Tn−2

Lecture 9: Recurrence Relations Characteristic Equation Method Matthew Fricke • Guess-and-Check is a very common approach (variations

Definition are method of iteration and substitution). Most useful Examples when you already have enough experience and intuition to Guess and be able to look at a recurrence and know the answer from Check comparison with other similar problems. Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • We will learn a method using the Characteristic Equation of a recurrence. • (The term Characteristic Equation comes from Linear Algebra) • The method works on second-order linear recurrence relations with constant coefficients. Annihilators generalize this method to any order. • Second order recurrence: refers to two previous values of the recurrence, e.g. Tn = Tn−1 + Tn−2

Lecture 9: Recurrence Relations Characteristic Equation Method Matthew Fricke • Guess-and-Check is a very common approach (variations

Definition are method of iteration and substitution). Most useful Examples when you already have enough experience and intuition to Guess and be able to look at a recurrence and know the answer from Check comparison with other similar problems. Binary Search

Characteristic • More analytical methods include The Master Method, Equation Method Recursion Trees, and Annihilators.

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • (The term Characteristic Equation comes from Linear Algebra) • The method works on second-order linear recurrence relations with constant coefficients. Annihilators generalize this method to any order. • Second order recurrence: refers to two previous values of the recurrence, e.g. Tn = Tn−1 + Tn−2

Lecture 9: Recurrence Relations Characteristic Equation Method Matthew Fricke • Guess-and-Check is a very common approach (variations

Definition are method of iteration and substitution). Most useful Examples when you already have enough experience and intuition to Guess and be able to look at a recurrence and know the answer from Check comparison with other similar problems. Binary Search

Characteristic • More analytical methods include The Master Method, Equation Method Recursion Trees, and Annihilators. The Fibonacci • We will learn a method using the Characteristic Equation Sequence of a recurrence. Golden Ratio

Gambler’s Ruin • The method works on second-order linear recurrence relations with constant coefficients. Annihilators generalize this method to any order. • Second order recurrence: refers to two previous values of the recurrence, e.g. Tn = Tn−1 + Tn−2

Lecture 9: Recurrence Relations Characteristic Equation Method Matthew Fricke • Guess-and-Check is a very common approach (variations

Definition are method of iteration and substitution). Most useful Examples when you already have enough experience and intuition to Guess and be able to look at a recurrence and know the answer from Check comparison with other similar problems. Binary Search

Characteristic • More analytical methods include The Master Method, Equation Method Recursion Trees, and Annihilators. The Fibonacci • We will learn a method using the Characteristic Equation Sequence of a recurrence. Golden Ratio • Gambler’s (The term Characteristic Equation comes from Linear Ruin Algebra) • Second order recurrence: refers to two previous values of the recurrence, e.g. Tn = Tn−1 + Tn−2

Lecture 9: Recurrence Relations Characteristic Equation Method Matthew Fricke • Guess-and-Check is a very common approach (variations

Definition are method of iteration and substitution). Most useful Examples when you already have enough experience and intuition to Guess and be able to look at a recurrence and know the answer from Check comparison with other similar problems. Binary Search

Characteristic • More analytical methods include The Master Method, Equation Method Recursion Trees, and Annihilators. The Fibonacci • We will learn a method using the Characteristic Equation Sequence of a recurrence. Golden Ratio • Gambler’s (The term Characteristic Equation comes from Linear Ruin Algebra) • The method works on second-order linear recurrence relations with constant coefficients. Annihilators generalize this method to any order. Lecture 9: Recurrence Relations Characteristic Equation Method Matthew Fricke • Guess-and-Check is a very common approach (variations

Definition are method of iteration and substitution). Most useful Examples when you already have enough experience and intuition to Guess and be able to look at a recurrence and know the answer from Check comparison with other similar problems. Binary Search

Characteristic • More analytical methods include The Master Method, Equation Method Recursion Trees, and Annihilators. The Fibonacci • We will learn a method using the Characteristic Equation Sequence of a recurrence. Golden Ratio • Gambler’s (The term Characteristic Equation comes from Linear Ruin Algebra) • The method works on second-order linear recurrence relations with constant coefficients. Annihilators generalize this method to any order. • Second order recurrence: refers to two previous values of the recurrence, e.g. Tn = Tn−1 + Tn−2 Lecture 9: Recurrence Relations Determining the Characteristic Matthew Fricke Equation

Definition

Examples

Guess and Check Definition: A second-order linear homogeneous recurrence Binary Search relation with constant coefficients is a recurrence relation of Characteristic Equation the form: Method ak = A · ak−1 + B · ak−2, ∃m ∈ Z 3 ∀k ∈ Z, k ≥ m, where A The Fibonacci Sequence and B are fixed real numbers with B 6= 0. Golden Ratio

Gambler’s Ruin (The part with m and k just allows for there to be some base cases.) • i.e. tk = A · tk−1 + B · tt−2 because each term is equal to A times the previous term plus B times the term before that. • Dividing by tk−2 gives t2 − At − B = 0. • This is true in general. A sequence of the form tk only satisfies the 2nd order homogeneous recurrence iff it satisfies t2 − At − B = 0. • We call this equation the Characteristic Equation.

Lecture 9: Recurrence Relations Determining the Characteristic Matthew Fricke Equation

Definition

Examples Guess and • Check A second-order linear homogeneous recurrence relation is 2 3 4 n Binary Search satisfied by the sequence 1, t, t , t , t ..., t

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Dividing by tk−2 gives t2 − At − B = 0. • This is true in general. A sequence of the form tk only satisfies the 2nd order homogeneous recurrence iff it satisfies t2 − At − B = 0. • We call this equation the Characteristic Equation.

Lecture 9: Recurrence Relations Determining the Characteristic Matthew Fricke Equation

Definition

Examples Guess and • Check A second-order linear homogeneous recurrence relation is 2 3 4 n Binary Search satisfied by the sequence 1, t, t , t , t ..., t k k−1 t−2 Characteristic • i.e. t = A · t + B · t because each term is equal to Equation Method A times the previous term plus B times the term before The Fibonacci that. Sequence

Golden Ratio

Gambler’s Ruin • This is true in general. A sequence of the form tk only satisfies the 2nd order homogeneous recurrence iff it satisfies t2 − At − B = 0. • We call this equation the Characteristic Equation.

Lecture 9: Recurrence Relations Determining the Characteristic Matthew Fricke Equation

Definition

Examples Guess and • Check A second-order linear homogeneous recurrence relation is 2 3 4 n Binary Search satisfied by the sequence 1, t, t , t , t ..., t k k−1 t−2 Characteristic • i.e. t = A · t + B · t because each term is equal to Equation Method A times the previous term plus B times the term before The Fibonacci that. Sequence k−2 2 Golden Ratio • Dividing by t gives t − At − B = 0.

Gambler’s Ruin • We call this equation the Characteristic Equation.

Lecture 9: Recurrence Relations Determining the Characteristic Matthew Fricke Equation

Definition

Examples Guess and • Check A second-order linear homogeneous recurrence relation is 2 3 4 n Binary Search satisfied by the sequence 1, t, t , t , t ..., t k k−1 t−2 Characteristic • i.e. t = A · t + B · t because each term is equal to Equation Method A times the previous term plus B times the term before The Fibonacci that. Sequence k−2 2 Golden Ratio • Dividing by t gives t − At − B = 0. Gambler’s • This is true in general. A sequence of the form tk only Ruin satisfies the 2nd order homogeneous recurrence iff it satisfies t2 − At − B = 0. Lecture 9: Recurrence Relations Determining the Characteristic Matthew Fricke Equation

Definition

Examples Guess and • Check A second-order linear homogeneous recurrence relation is 2 3 4 n Binary Search satisfied by the sequence 1, t, t , t , t ..., t k k−1 t−2 Characteristic • i.e. t = A · t + B · t because each term is equal to Equation Method A times the previous term plus B times the term before The Fibonacci that. Sequence k−2 2 Golden Ratio • Dividing by t gives t − At − B = 0. Gambler’s • This is true in general. A sequence of the form tk only Ruin satisfies the 2nd order homogeneous recurrence iff it satisfies t2 − At − B = 0. • We call this equation the Characteristic Equation. • This is of the form ak = 1 · ak−1 + B · ak−2 where A = 1, and B = 2 • So the characteristic equation t2 − At − B = 0 is t2 − t − 2 = 0. • Now we need to find t so that the characteristic equation is satisfied, i.e. equal to zero. • Recall all the fun you had finding roots of quadratic formulas in Algebra I!

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples

Guess and • Find a sequence that satisfies ak = ak−1 + 2ak−2 Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • So the characteristic equation t2 − At − B = 0 is t2 − t − 2 = 0. • Now we need to find t so that the characteristic equation is satisfied, i.e. equal to zero. • Recall all the fun you had finding roots of quadratic formulas in Algebra I!

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples

Guess and • Find a sequence that satisfies ak = ak−1 + 2ak−2 Check • This is of the form ak = 1 · ak−1 + B · ak−2 where A = 1, Binary Search and B = 2 Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Now we need to find t so that the characteristic equation is satisfied, i.e. equal to zero. • Recall all the fun you had finding roots of quadratic formulas in Algebra I!

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples

Guess and • Find a sequence that satisfies ak = ak−1 + 2ak−2 Check • This is of the form ak = 1 · ak−1 + B · ak−2 where A = 1, Binary Search and B = 2 Characteristic Equation 2 Method • So the characteristic equation t − At − B = 0 is 2 The Fibonacci t − t − 2 = 0. Sequence

Golden Ratio

Gambler’s Ruin • Recall all the fun you had finding roots of quadratic formulas in Algebra I!

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples

Guess and • Find a sequence that satisfies ak = ak−1 + 2ak−2 Check • This is of the form ak = 1 · ak−1 + B · ak−2 where A = 1, Binary Search and B = 2 Characteristic Equation 2 Method • So the characteristic equation t − At − B = 0 is 2 The Fibonacci t − t − 2 = 0. Sequence • Golden Ratio Now we need to find t so that the characteristic equation

Gambler’s is satisfied, i.e. equal to zero. Ruin Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples

Guess and • Find a sequence that satisfies ak = ak−1 + 2ak−2 Check • This is of the form ak = 1 · ak−1 + B · ak−2 where A = 1, Binary Search and B = 2 Characteristic Equation 2 Method • So the characteristic equation t − At − B = 0 is 2 The Fibonacci t − t − 2 = 0. Sequence • Golden Ratio Now we need to find t so that the characteristic equation

Gambler’s is satisfied, i.e. equal to zero. Ruin • Recall all the fun you had finding roots of quadratic formulas in Algebra I! • t2 − t − 2 = (t − 2)(t + 1) • The roots are 2 and -1. • So the only sequences of the form tn that satisfy the recurrence are: 0 1 2 3 4 rn = 2 , 2 , 2 , 2 , 2 ... and 0 1 2 3 4 sn = (−1) , (−1) , (−1) , (−1) , (−1) ... • AND any linear combination of these sequences satisfies the recurrence: an = C · rn + D · sn, C and D can be any numbers.

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples • Find a sequence that satisfies ak = ak−1 + 2ak−2 Guess and Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • The roots are 2 and -1. • So the only sequences of the form tn that satisfy the recurrence are: 0 1 2 3 4 rn = 2 , 2 , 2 , 2 , 2 ... and 0 1 2 3 4 sn = (−1) , (−1) , (−1) , (−1) , (−1) ... • AND any linear combination of these sequences satisfies the recurrence: an = C · rn + D · sn, C and D can be any numbers.

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples • Find a sequence that satisfies ak = ak−1 + 2ak−2 Guess and Check • t2 − t − 2 = (t − 2)(t + 1) Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • So the only sequences of the form tn that satisfy the recurrence are: 0 1 2 3 4 rn = 2 , 2 , 2 , 2 , 2 ... and 0 1 2 3 4 sn = (−1) , (−1) , (−1) , (−1) , (−1) ... • AND any linear combination of these sequences satisfies the recurrence: an = C · rn + D · sn, C and D can be any numbers.

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples • Find a sequence that satisfies ak = ak−1 + 2ak−2 Guess and Check • t2 − t − 2 = (t − 2)(t + 1) Binary Search • The roots are 2 and -1. Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • AND any linear combination of these sequences satisfies the recurrence: an = C · rn + D · sn, C and D can be any numbers.

Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples • Find a sequence that satisfies ak = ak−1 + 2ak−2 Guess and Check • t2 − t − 2 = (t − 2)(t + 1) Binary Search • The roots are 2 and -1. Characteristic Equation • n Method So the only sequences of the form t that satisfy the

The Fibonacci recurrence are: Sequence 0 1 2 3 4 rn = 2 , 2 , 2 , 2 , 2 ... and Golden Ratio 0 1 2 3 4 sn = (−1) , (−1) , (−1) , (−1) , (−1) ... Gambler’s Ruin Lecture 9: Recurrence Relations Example Matthew Fricke

Definition

Examples • Find a sequence that satisfies ak = ak−1 + 2ak−2 Guess and Check • t2 − t − 2 = (t − 2)(t + 1) Binary Search • The roots are 2 and -1. Characteristic Equation • n Method So the only sequences of the form t that satisfy the

The Fibonacci recurrence are: Sequence 0 1 2 3 4 rn = 2 , 2 , 2 , 2 , 2 ... and Golden Ratio 0 1 2 3 4 sn = (−1) , (−1) , (−1) , (−1) , (−1) ... Gambler’s Ruin • AND any linear combination of these sequences satisfies the recurrence: an = C · rn + D · sn, C and D can be any numbers. Lecture 9: Recurrence Relations Distinct Roots Matthew Fricke

Definition

Examples Guess and All that leads us to the Distinct Roots Theorem. Suppose a Check sequence a , a , a ,... satisfies a recurrence relation Binary Search 0 1 2

Characteristic ak = A · ak−1 + B · ak−1 for some real numbers A and B and k Equation > 2. Method n n The Fibonacci Then a0, a1, a2,... satisfies the closed form an = C · r + D · s Sequence if the characteristic equation t2 − At − B = 0 has two distinct Golden Ratio roots r and s. Where C and D are solutions to the system of Gambler’s 0 0 1 1 Ruin equations a0 = C · r + D · s and a1 = C · r + D · s . Equivalently a0 = C + D and a1 = C · r + D · s Lecture 9: Recurrence Relations Single Root Theorem Matthew Fricke

Definition

Examples

Guess and and the Single Root Theorem. Suppose a sequence Check a0, a1, a2,... satisfies a recurrence relation Binary Search ak = A · ak−1 + B · ak−1 for some real numbers A and B and k Characteristic Equation > 2. Method Then a0, a1, a2,... satisfies the closed form The Fibonacci n n Sequence an = C · r + nD · r if the characteristic equation 2 Golden Ratio t − At − B = 0 has a single (perhaps repeated) root r. Where Gambler’s C and D are solutions to the system of equations Ruin 0 0 1 1 a0 = C · r + nD · r and a1 = C · r + nD · r . Equivalently a0 = C + D and a1 = C · r + nD · r. • Recall the Fibonacci sequence is Fn = Fn−1 + Fn−2, with base cases F0 = 0, F1 = 1. • The Fibonacci sequence is a second-order and homogeneous with constant coefficients: A=1, B=1 • The characteristic equation is t2 − t − 1 = 0

• Solving√ this equation for t: b± b2−4ac t = 2a for any quadratic polynomial: at2 + bt + c = 0 (Quadratic Formula). √ √ 1± 1−4(−1) 1± 5 • t = 2 = 2 . Two distinct roots.

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition • Now we are equipped to solve recurrences like the Examples

Guess and Fibonacci sequence. Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • The Fibonacci sequence is a second-order and homogeneous with constant coefficients: A=1, B=1 • The characteristic equation is t2 − t − 1 = 0

• Solving√ this equation for t: b± b2−4ac t = 2a for any quadratic polynomial: at2 + bt + c = 0 (Quadratic Formula). √ √ 1± 1−4(−1) 1± 5 • t = 2 = 2 . Two distinct roots.

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition • Now we are equipped to solve recurrences like the Examples

Guess and Fibonacci sequence. Check • Recall the Fibonacci sequence is Fn = Fn−1 + Fn−2, with Binary Search base cases F0 = 0, F1 = 1. Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • The characteristic equation is t2 − t − 1 = 0

• Solving√ this equation for t: b± b2−4ac t = 2a for any quadratic polynomial: at2 + bt + c = 0 (Quadratic Formula). √ √ 1± 1−4(−1) 1± 5 • t = 2 = 2 . Two distinct roots.

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition • Now we are equipped to solve recurrences like the Examples

Guess and Fibonacci sequence. Check • Recall the Fibonacci sequence is Fn = Fn−1 + Fn−2, with Binary Search base cases F0 = 0, F1 = 1. Characteristic Equation • Method The Fibonacci sequence is a second-order and

The Fibonacci homogeneous with constant coefficients: A=1, B=1 Sequence

Golden Ratio

Gambler’s Ruin • Solving√ this equation for t: b± b2−4ac t = 2a for any quadratic polynomial: at2 + bt + c = 0 (Quadratic Formula). √ √ 1± 1−4(−1) 1± 5 • t = 2 = 2 . Two distinct roots.

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition • Now we are equipped to solve recurrences like the Examples

Guess and Fibonacci sequence. Check • Recall the Fibonacci sequence is Fn = Fn−1 + Fn−2, with Binary Search base cases F0 = 0, F1 = 1. Characteristic Equation • Method The Fibonacci sequence is a second-order and

The Fibonacci homogeneous with constant coefficients: A=1, B=1 Sequence • The characteristic equation is t2 − t − 1 = 0 Golden Ratio

Gambler’s Ruin √ √ 1± 1−4(−1) 1± 5 • t = 2 = 2 . Two distinct roots.

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition • Now we are equipped to solve recurrences like the Examples

Guess and Fibonacci sequence. Check • Recall the Fibonacci sequence is Fn = Fn−1 + Fn−2, with Binary Search base cases F0 = 0, F1 = 1. Characteristic Equation • Method The Fibonacci sequence is a second-order and

The Fibonacci homogeneous with constant coefficients: A=1, B=1 Sequence • The characteristic equation is t2 − t − 1 = 0 Golden Ratio Gambler’s • Solving√ this equation for t: Ruin b± b2−4ac t = 2a for any quadratic polynomial: at2 + bt + c = 0 (Quadratic Formula). Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition • Now we are equipped to solve recurrences like the Examples

Guess and Fibonacci sequence. Check • Recall the Fibonacci sequence is Fn = Fn−1 + Fn−2, with Binary Search base cases F0 = 0, F1 = 1. Characteristic Equation • Method The Fibonacci sequence is a second-order and

The Fibonacci homogeneous with constant coefficients: A=1, B=1 Sequence • The characteristic equation is t2 − t − 1 = 0 Golden Ratio Gambler’s • Solving√ this equation for t: Ruin b± b2−4ac t = 2a for any quadratic polynomial: at2 + bt + c = 0 (Quadratic Formula). √ √ 1± 1−4(−1) 1± 5 • t = 2 = 2 . Two distinct roots. • so by the distinct root theorem: √ n √ n  1+ 5   1− 5  Fn = C 2 + D 2 • Now we need to find the values of C and D using the initial conditions (differential equations), base cases (recurrences).

• The base cases are F0 = 0 and F1 = 1. • So we need to solve the system of equations: F1 = 1 = C + D F2 = 1 = Cρ1 + Dρ2 √ √ • Solving this system gives C = 1+√ 5 , D = −1+√ 5 One way 2 5 2 5 to solve this system using the method of partial fractions. If you know this method the setup is: z 1  1 1  F (z) = 2 = √ − 1−z−z 5 1−ρ1z 1−ρ2z

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew √ Fricke 1± 5 • t = 2 . Two distinct roots, ρ1 and ρ2. Definition

Examples

Guess and Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • Now we need to find the values of C and D using the initial conditions (differential equations), base cases (recurrences).

• The base cases are F0 = 0 and F1 = 1. • So we need to solve the system of equations: F1 = 1 = C + D F2 = 1 = Cρ1 + Dρ2 √ √ • Solving this system gives C = 1+√ 5 , D = −1+√ 5 One way 2 5 2 5 to solve this system using the method of partial fractions. If you know this method the setup is: z 1  1 1  F (z) = 2 = √ − 1−z−z 5 1−ρ1z 1−ρ2z

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew √ Fricke 1± 5 • t = 2 . Two distinct roots, ρ1 and ρ2. Definition • so by the distinct root theorem: √ n √ n Examples  1+ 5   1− 5  Guess and Fn = C 2 + D 2 Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • The base cases are F0 = 0 and F1 = 1. • So we need to solve the system of equations: F1 = 1 = C + D F2 = 1 = Cρ1 + Dρ2 √ √ • Solving this system gives C = 1+√ 5 , D = −1+√ 5 One way 2 5 2 5 to solve this system using the method of partial fractions. If you know this method the setup is: z 1  1 1  F (z) = 2 = √ − 1−z−z 5 1−ρ1z 1−ρ2z

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew √ Fricke 1± 5 • t = 2 . Two distinct roots, ρ1 and ρ2. Definition • so by the distinct root theorem: √ n √ n Examples  1+ 5   1− 5  Guess and Fn = C 2 + D 2 Check • Now we need to find the values of C and D using the Binary Search

Characteristic initial conditions (differential equations), base cases Equation (recurrences). Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin • So we need to solve the system of equations: F1 = 1 = C + D F2 = 1 = Cρ1 + Dρ2 √ √ • Solving this system gives C = 1+√ 5 , D = −1+√ 5 One way 2 5 2 5 to solve this system using the method of partial fractions. If you know this method the setup is: z 1  1 1  F (z) = 2 = √ − 1−z−z 5 1−ρ1z 1−ρ2z

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew √ Fricke 1± 5 • t = 2 . Two distinct roots, ρ1 and ρ2. Definition • so by the distinct root theorem: √ n √ n Examples  1+ 5   1− 5  Guess and Fn = C 2 + D 2 Check • Now we need to find the values of C and D using the Binary Search

Characteristic initial conditions (differential equations), base cases Equation (recurrences). Method The Fibonacci • The base cases are F0 = 0 and F1 = 1. Sequence

Golden Ratio

Gambler’s Ruin √ √ • Solving this system gives C = 1+√ 5 , D = −1+√ 5 One way 2 5 2 5 to solve this system using the method of partial fractions. If you know this method the setup is: z 1  1 1  F (z) = 2 = √ − 1−z−z 5 1−ρ1z 1−ρ2z

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew √ Fricke 1± 5 • t = 2 . Two distinct roots, ρ1 and ρ2. Definition • so by the distinct root theorem: √ n √ n Examples  1+ 5   1− 5  Guess and Fn = C 2 + D 2 Check • Now we need to find the values of C and D using the Binary Search

Characteristic initial conditions (differential equations), base cases Equation (recurrences). Method The Fibonacci • The base cases are F0 = 0 and F1 = 1. Sequence

Golden Ratio • So we need to solve the system of equations:

Gambler’s F1 = 1 = C + D Ruin F2 = 1 = Cρ1 + Dρ2 Lecture 9: Recurrence Relations Fibonacci Sequence Matthew √ Fricke 1± 5 • t = 2 . Two distinct roots, ρ1 and ρ2. Definition • so by the distinct root theorem: √ n √ n Examples  1+ 5   1− 5  Guess and Fn = C 2 + D 2 Check • Now we need to find the values of C and D using the Binary Search

Characteristic initial conditions (differential equations), base cases Equation (recurrences). Method The Fibonacci • The base cases are F0 = 0 and F1 = 1. Sequence

Golden Ratio • So we need to solve the system of equations:

Gambler’s F1 = 1 = C + D Ruin F2 = 1 = Cρ1 + Dρ2 √ √ • Solving this system gives C = 1+√ 5 , D = −1+√ 5 One way 2 5 2 5 to solve this system using the method of partial fractions. If you know this method the setup is: z 1  1 1  F (z) = 2 = √ − 1−z−z 5 1−ρ1z 1−ρ2z • Seems strange√ that this sequence is made up of integers but we have 5 throughout. √ 1+ 5 • It turns out that this value 2 is very special. It is called the Golden Ratio or Golden Mean and has the symbol Φ • During the Renaissance Φ was known as the Divine Proportion

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition Examples • So we have solved the Fibonacci recurrence: Guess and Check

Binary Search √ √ n √ √ n 1+ 5  1+ 5  −1+ 5  1− 5  Characteristic Fn = √ + √ Equation 2 5 2 2 5 2 Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin √ 1+ 5 • It turns out that this value 2 is very special. It is called the Golden Ratio or Golden Mean and has the symbol Φ • During the Renaissance Φ was known as the Divine Proportion

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition Examples • So we have solved the Fibonacci recurrence: Guess and Check

Binary Search √ √ n √ √ n 1+ 5  1+ 5  −1+ 5  1− 5  Characteristic Fn = √ + √ Equation 2 5 2 2 5 2 Method • Seems strange that this sequence is made up of integers The Fibonacci √ Sequence but we have 5 throughout. Golden Ratio

Gambler’s Ruin • During the Renaissance Φ was known as the Divine Proportion

Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition Examples • So we have solved the Fibonacci recurrence: Guess and Check

Binary Search √ √ n √ √ n 1+ 5  1+ 5  −1+ 5  1− 5  Characteristic Fn = √ + √ Equation 2 5 2 2 5 2 Method • Seems strange that this sequence is made up of integers The Fibonacci √ Sequence but we have 5 throughout. √ Golden Ratio 1+ 5 • It turns out that this value 2 is very special. It is called Gambler’s Ruin the Golden Ratio or Golden Mean and has the symbol Φ Lecture 9: Recurrence Relations Fibonacci Sequence Matthew Fricke

Definition Examples • So we have solved the Fibonacci recurrence: Guess and Check

Binary Search √ √ n √ √ n 1+ 5  1+ 5  −1+ 5  1− 5  Characteristic Fn = √ + √ Equation 2 5 2 2 5 2 Method • Seems strange that this sequence is made up of integers The Fibonacci √ Sequence but we have 5 throughout. √ Golden Ratio 1+ 5 • It turns out that this value 2 is very special. It is called Gambler’s Ruin the Golden Ratio or Golden Mean and has the symbol Φ • During the Renaissance Φ was known as the Divine Proportion Lecture 9: Recurrence Relations The Golden Ratio Matthew Fricke

Definition

Examples

Guess and Check

Binary Search

Characteristic Equation Method

The Fibonacci Sequence

Golden Ratio

Gambler’s Ruin Lecture 9: Recurrence Relations Gambler’s Ruin Matthew Fricke

Definition Examples Consider a game of chance. You (the player) will win $1 or lose Guess and Check $1 depending on the outcome of a coin toss. If the coin comes

Binary Search up heads you win if it comes up tails you lose.

Characteristic Equation Method You decide to play until one of two conditions are met: The Fibonacci 1) You run out of money. Sequence 2) or you have won a target amount of money, M. Golden Ratio

Gambler’s Ruin The question we would like to answer is the probability of you going bust given a starting amount of money and the target value, M. Lecture 9: Recurrence Relations Gambler’s Ruin Matthew Fricke

Definition

Examples • Notice that the amount of money you have in the first Guess and Check round is equal to your starting amount. Binary Search • Otherwise the amount of money you have depends on the Characteristic Equation amount of money you had previous round coupled with the Method outcome of the previous coin toss. The Fibonacci Sequence • So we have a sequence of values for the probability of Golden Ratio going bust Pn given $n that depends on previous values of Gambler’s Ruin Pk . • In other words we have a recurrence that we can try to define and solve. Lecture 9: Recurrence Relations Gambler’s Ruin Matthew Fricke

Definition

Examples

Guess and Check • The probability of a player having $k, i.e. Pk transitioning Binary Search 1 into Pk−1 (losing a dollar) is 2 . Characteristic Equation • The probability of transitioning to state Pk+1 (winning a Method dollar) is also 1 . The Fibonacci 2 Sequence • These outcomes are related by xor so we can use the Golden Ratio addition rule of discrete probability. Gambler’s Ruin 1 1 • Therefore Pk = 2 Pk−1 + 2 Pk+1. Lecture 9: Recurrence Relations Gambler’s Ruin Matthew Fricke

Definition

Examples

Guess and Check 1 1 • Therefore Pk = 2 Pk−1 + 2 Pk+1. Binary Search • Rewriting in a form we are more used to: Characteristic Equation 0 = −2Pk + Pk−1 + Pk+1. Method • The Fibonacci Having the coefficient 2 on Pk is awkward but we can shift Sequence the sequence index by -1. Golden Ratio • 0 = −2Pk−1 + Pk−2 + Pk . Gambler’s Ruin • Rewriting: Pk = 2Pk−1 − Pk−2. Lecture 9: Recurrence Relations Gambler’s Ruin Matthew Fricke

Definition • Now we have a second order homogeneous recurrence with Examples constant coefficients. Guess and Check • We know how to solve those using the Characteristic Binary Search Equation method. Characteristic Equation • What about the base cases though. Here the sequence Method ends under two circumstances: The Fibonacci Sequence • The player wins a total of $M or the player loses all their Golden Ratio money. Gambler’s Ruin • So the base cases (more like boundary conditions in this case) are PM = 0 and P0 = 1. • Since the Probability of going bust when you have $0 is 1. The Probability of going bust when you have $M is 0. Lecture 9: Recurrence Relations Gambler’s Ruin Matthew Fricke • Now we have everything we need to solve the recurrence. Definition 2 Examples • Characteristic Equation: t − 2t + 1 = 0 since A = 2 and

Guess and B = −1 in Pk = APk−1 + BPk−2 and the characteristic Check equation is t2 − At + B = 0. Binary Search • Characteristic Now we find the roots of the characteristic polynomial. Equation Method • Factoring: (t − 1)(t − 1) The repeated root is ρ = 1. The Fibonacci • Using the single root theorem: P = C(1)n + nD(1)n. Sequence n Golden Ratio • Solving for C and D: Gambler’s P0 = 1 = C + (0)D Ruin PM = 0 = C + (M)D ∴ C = 1 1 ∴ D = − M 1 ∴ Pn = 1 − n M M 1 M−n ∴ Pn = M − n M = M Lecture 9: Recurrence Relations Gambler’s Ruin Matthew Fricke

Definition

Examples

Guess and • Now we have a closed form for the recurrence and can Check answer the question for any target amount and starting Binary Search amount of money. Characteristic Equation Method • Example: What is the probability of going bust if you start

The Fibonacci with $30 and your goal is $120. Sequence 120−30 • Answer: M = 120, n = 30. P30 = = 75%. Golden Ratio 120

Gambler’s • Another Examples: M = 500, n = 50. Ruin 500−50 P50 = 500 = 90% chance of going bust before winning $500.