Recurrences, Part 1 Troy Vasiga Centre for Education in Mathematics - - PowerPoint PPT Presentation

recurrences part 1
SMART_READER_LITE
LIVE PREVIEW

Recurrences, Part 1 Troy Vasiga Centre for Education in Mathematics - - PowerPoint PPT Presentation

Recurrences, Part 1 Troy Vasiga Centre for Education in Mathematics and Computing Faculty of Mathematics, University of Waterloo cemc.uwaterloo.ca WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING Outline Short


slide-1
SLIDE 1

Recurrences, Part 1

Troy Vasiga Centre for Education in Mathematics and Computing Faculty of Mathematics, University of Waterloo cemc.uwaterloo.ca

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-2
SLIDE 2

Outline

  • Short biography of the speaker
  • Recursion
  • Why recursion is good
  • Work on problems

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-3
SLIDE 3

Short biography of the speaker

  • Academic background:
  • B.Math (Computer Science and Combinatorics and

Optimization, Double Degree), UW, 19

  • M.Math (Combinatorics and Optimization) [thesis topic:

“α-resolvable designs of block size 4”], UW, 19

  • B.Ed, UBC, 19
  • Ph.D (Computer Science) “Error detection and correction in

number-theoretic algorithms”, UW, 20

  • Current Position:
  • Lecturer, David R. Cheriton School of Computer Science
  • Associate Director, Centre for Education in Mathematics and

Computing

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-4
SLIDE 4

Short biography of the speaker

  • Academic life
  • teach (mostly) first- and second-year CS courses (CS 115, 116,

135, 241)

  • coordinate the Canadian Computing Competition (organize

problem creation, publication of results, communication with teachers, select Stage 2 invitees, train and supervise the Canadian IOI team)

  • do lots of school visits (elementary and secondary schools in

Ontario, Malaysia, Singapore, China, Hong Kong)

  • reviewer and grader for other math competitions (Euclid,

CIMC/CSMC)

  • sit on or chair various CS committees (Undergraduate

Recruiting, Outreach, Scholarship committees)

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-5
SLIDE 5

Short biography of the speaker

  • Non-academic life
  • bicycle to work every day (yes, every day)
  • enjoy working out at the gym regularly
  • enjoy travel (through work and outside of work)
  • love playing Uno, Sleeping Queens, and Clue and reading with

daughter Natalie

  • love dinner and movies with lovely wife Krista
  • enjoy hanging out with neighbourhood friends

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-6
SLIDE 6

Recursion

  • Definition: see Recursion
  • Real Definition:

Defining a function/structure using the function/structure itself in the definition

  • To repeat something, you must recurse
  • A better definition of recursion:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-7
SLIDE 7

Recursion

  • Definition: see Recursion
  • Real Definition:

Defining a function/structure using the function/structure itself in the definition

  • To repeat something, you must recurse
  • A better definition of recursion: if you don’t understand

recursion, see recursion.

  • Notice that recursion requires a base case as well as recursive

cases.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-8
SLIDE 8

Natural Recursion

Why is recursion good?

  • Easier to determine what the function does
  • A natural way of seeing the world

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-9
SLIDE 9

Recursion Examples: Babushka Dolls

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-10
SLIDE 10

Recursion Examples: Shells

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-11
SLIDE 11

Recursion Examples: The spiral of life

  • I was created by my parents
  • My parents were created by their parents
  • My grandparents were created by their parents
  • ....
  • Base case?

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-12
SLIDE 12

Recursive space filling: M. C. Escher

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-13
SLIDE 13

Recursive space filling: M. C. Escher

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-14
SLIDE 14

Recurrence relations in sequences

A sequence a0, a1, a2, ... can be specified recursively by giving

  • base cases (aka “initial conditions”)
  • a recursive definition

For example, we could have: a0 = a1 = 5 as the base cases and an = 2an−1 − an−2 We would like to solve this: that is, find a closed form (ideally, a number or formula depending on n) for an.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-15
SLIDE 15

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-16
SLIDE 16

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-17
SLIDE 17

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 = 5 a2 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-18
SLIDE 18

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 = 5 a2 = 2(5) − 0 = 10 a3 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-19
SLIDE 19

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 = 5 a2 = 2(5) − 0 = 10 a3 = 2(10) − 5 = 15 a4 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-20
SLIDE 20

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 = 5 a2 = 2(5) − 0 = 10 a3 = 2(10) − 5 = 15 a4 = 2(15) − 10 = 20 a5 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-21
SLIDE 21

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 = 5 a2 = 2(5) − 0 = 10 a3 = 2(10) − 5 = 15 a4 = 2(15) − 10 = 20 a5 = 2(20) − 15 = 25

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-22
SLIDE 22

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 = 5 a2 = 2(5) − 0 = 10 a3 = 2(10) − 5 = 15 a4 = 2(15) − 10 = 20 a5 = 2(20) − 15 = 25 It looks like the closed form for this recurrence is: an = 5n

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-23
SLIDE 23

“Guess” and check

Write out the first few terms, and try to find a pattern. a0 = a1 = 5 a2 = 2(5) − 0 = 10 a3 = 2(10) − 5 = 15 a4 = 2(15) − 10 = 20 a5 = 2(20) − 15 = 25 It looks like the closed form for this recurrence is: an = 5n But we would like to prove it!

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-24
SLIDE 24

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-25
SLIDE 25

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

  • 1. show the result holds for the base case(s): this is usually, but

not always, easy

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-26
SLIDE 26

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

  • 1. show the result holds for the base case(s): this is usually, but

not always, easy

  • 2. assume the result holds for all values ≤ k for some k which is

at least as big as the base case(s)

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-27
SLIDE 27

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

  • 1. show the result holds for the base case(s): this is usually, but

not always, easy

  • 2. assume the result holds for all values ≤ k for some k which is

at least as big as the base case(s)

  • this step is known as the inductive hypothesis

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-28
SLIDE 28

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

  • 1. show the result holds for the base case(s): this is usually, but

not always, easy

  • 2. assume the result holds for all values ≤ k for some k which is

at least as big as the base case(s)

  • this step is known as the inductive hypothesis
  • when we make this hypothesis, we are using strong induction

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-29
SLIDE 29

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

  • 1. show the result holds for the base case(s): this is usually, but

not always, easy

  • 2. assume the result holds for all values ≤ k for some k which is

at least as big as the base case(s)

  • this step is known as the inductive hypothesis
  • when we make this hypothesis, we are using strong induction
  • there is a variant known as weak induction where we assume

the result holds only for one particular value of k

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-30
SLIDE 30

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

  • 1. show the result holds for the base case(s): this is usually, but

not always, easy

  • 2. assume the result holds for all values ≤ k for some k which is

at least as big as the base case(s)

  • this step is known as the inductive hypothesis
  • when we make this hypothesis, we are using strong induction
  • there is a variant known as weak induction where we assume

the result holds only for one particular value of k

  • 3. show the result holds for k + 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-31
SLIDE 31

Mathematical Induction

Mathematical induction is the mirror image of recursion. When we try to prove a result using induction, we need to do three things:

  • 1. show the result holds for the base case(s): this is usually, but

not always, easy

  • 2. assume the result holds for all values ≤ k for some k which is

at least as big as the base case(s)

  • this step is known as the inductive hypothesis
  • when we make this hypothesis, we are using strong induction
  • there is a variant known as weak induction where we assume

the result holds only for one particular value of k

  • 3. show the result holds for k + 1
  • this step is called the inductive step

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-32
SLIDE 32

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-33
SLIDE 33

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-34
SLIDE 34

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-35
SLIDE 35

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-36
SLIDE 36

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n. We now prove the result for n = k + 1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-37
SLIDE 37

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n. We now prove the result for n = k + 1. We need to show that ak+1 = 5(k + 1). But, we know that ak+1 = 2ak − ak−1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-38
SLIDE 38

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n. We now prove the result for n = k + 1. We need to show that ak+1 = 5(k + 1). But, we know that ak+1 = 2ak − ak−1 = 2(5k) − 5(k − 1)

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-39
SLIDE 39

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n. We now prove the result for n = k + 1. We need to show that ak+1 = 5(k + 1). But, we know that ak+1 = 2ak − ak−1 = 2(5k) − 5(k − 1) = 10k − 5k + 5

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-40
SLIDE 40

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n. We now prove the result for n = k + 1. We need to show that ak+1 = 5(k + 1). But, we know that ak+1 = 2ak − ak−1 = 2(5k) − 5(k − 1) = 10k − 5k + 5 = 5k + 5

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-41
SLIDE 41

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n. We now prove the result for n = k + 1. We need to show that ak+1 = 5(k + 1). But, we know that ak+1 = 2ak − ak−1 = 2(5k) − 5(k − 1) = 10k − 5k + 5 = 5k + 5 = 5(k + 1)

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-42
SLIDE 42

Our first inductive proof

Prove: If a0 = 0, a1 = 5 and an = 2an−1 − an−2, then an = 5n for all n ≥ 0. Proof: By (strong) mathematical induction. If n = 0, then 5n = 0 = a0. If n = 1, then 5n = 5 = a1. Thus, the result holds for the base cases. Assume that for all values of n such that n ≤ k, the result holds. That is, for any n ≤ k, we know that an = 5n. We now prove the result for n = k + 1. We need to show that ak+1 = 5(k + 1). But, we know that ak+1 = 2ak − ak−1 = 2(5k) − 5(k − 1) = 10k − 5k + 5 = 5k + 5 = 5(k + 1) which proves the result.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-43
SLIDE 43

Exercise

Suppose you have: a0 = 1 an = 2an−1 + 1 (This is sometimes known as the Tower of Hanoi recurrence). Find a closed form, and prove that it is correct using mathematical induction.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-44
SLIDE 44

Solution

Start with some values: a0 = 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-45
SLIDE 45

Solution

Start with some values: a0 = 1 a1 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-46
SLIDE 46

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-47
SLIDE 47

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-48
SLIDE 48

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 = 2(3) + 1 = 7

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-49
SLIDE 49

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 = 2(3) + 1 = 7 a3 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-50
SLIDE 50

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 = 2(3) + 1 = 7 a3 = 2(7) + 1 = 15

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-51
SLIDE 51

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 = 2(3) + 1 = 7 a3 = 2(7) + 1 = 15 a4 =

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-52
SLIDE 52

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 = 2(3) + 1 = 7 a3 = 2(7) + 1 = 15 a4 = 2(15) + 1 = 31

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-53
SLIDE 53

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 = 2(3) + 1 = 7 a3 = 2(7) + 1 = 15 a4 = 2(15) + 1 = 31

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-54
SLIDE 54

Solution

Start with some values: a0 = 1 a1 = 2(1) + 1 = 3 a2 = 2(3) + 1 = 7 a3 = 2(7) + 1 = 15 a4 = 2(15) + 1 = 31 We conjecture that an = 2n+1 − 1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-55
SLIDE 55

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-56
SLIDE 56

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1 Assume that for all n ≤ k (k ≥ 0), we have an = 2n+1 − 1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-57
SLIDE 57

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1 Assume that for all n ≤ k (k ≥ 0), we have an = 2n+1 − 1. We need to show that the result holds when n = k + 1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-58
SLIDE 58

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1 Assume that for all n ≤ k (k ≥ 0), we have an = 2n+1 − 1. We need to show that the result holds when n = k + 1. ak+1 = 2ak + 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-59
SLIDE 59

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1 Assume that for all n ≤ k (k ≥ 0), we have an = 2n+1 − 1. We need to show that the result holds when n = k + 1. ak+1 = 2ak + 1 = 2(2k+1 − 1) + 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-60
SLIDE 60

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1 Assume that for all n ≤ k (k ≥ 0), we have an = 2n+1 − 1. We need to show that the result holds when n = k + 1. ak+1 = 2ak + 1 = 2(2k+1 − 1) + 1 = 2k+2 − 2 + 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-61
SLIDE 61

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1 Assume that for all n ≤ k (k ≥ 0), we have an = 2n+1 − 1. We need to show that the result holds when n = k + 1. ak+1 = 2ak + 1 = 2(2k+1 − 1) + 1 = 2k+2 − 2 + 1 = 2k+2 − 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-62
SLIDE 62

Proof of closed form

We only have one base case: a0 = 1 = 2(0+1) − 1 Assume that for all n ≤ k (k ≥ 0), we have an = 2n+1 − 1. We need to show that the result holds when n = k + 1. ak+1 = 2ak + 1 = 2(2k+1 − 1) + 1 = 2k+2 − 2 + 1 = 2k+2 − 1 which proves the result.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-63
SLIDE 63

Formalizing a formula

Guessing a closed form seems like a not very extendible idea, even for very “simple” things like:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-64
SLIDE 64

Formalizing a formula

Guessing a closed form seems like a not very extendible idea, even for very “simple” things like: f0 = f1 = 1 fn = fn−1 + fn−2

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-65
SLIDE 65

Formalizing a formula

Guessing a closed form seems like a not very extendible idea, even for very “simple” things like: f0 = f1 = 1 fn = fn−1 + fn−2 A recurrence is called linear if each term of a sequence defined by the recurrence is linear function (i.e., only multiplied by a constant

  • r has a constant added) of earlier terms in the sequence.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-66
SLIDE 66

Formalizing a formula

Guessing a closed form seems like a not very extendible idea, even for very “simple” things like: f0 = f1 = 1 fn = fn−1 + fn−2 A recurrence is called linear if each term of a sequence defined by the recurrence is linear function (i.e., only multiplied by a constant

  • r has a constant added) of earlier terms in the sequence.

So, something like qn = (qn−1)2 + 4 is not a linear recurrence, but all the other recurrences we have seen so far are linear.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-67
SLIDE 67

More formalism

A linear homogeneous recurrence relation of degree k is a relation

  • f the form

an = c1an−1 + c2an−2 + . . . + ckan−k where each ci is a real number and ck = 0.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-68
SLIDE 68

More formalism

A linear homogeneous recurrence relation of degree k is a relation

  • f the form

an = c1an−1 + c2an−2 + . . . + ckan−k where each ci is a real number and ck = 0. Such a recurrence must include k initial conditions: a0 = V0 a1 = V1 . . . ak = Vk

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-69
SLIDE 69

Characteristic equation

Let’s suppose that the closed form to a recurrence an = c1an−1 + c2an−2 + · · · + ckan−k looks like an = rn for some constant r.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-70
SLIDE 70

Characteristic equation

Let’s suppose that the closed form to a recurrence an = c1an−1 + c2an−2 + · · · + ckan−k looks like an = rn for some constant r. That would mean:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-71
SLIDE 71

Characteristic equation

Let’s suppose that the closed form to a recurrence an = c1an−1 + c2an−2 + · · · + ckan−k looks like an = rn for some constant r. That would mean: rn = c1rn−1 + c2rn−2 + · · · + ckrn−k

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-72
SLIDE 72

Characteristic equation

Let’s suppose that the closed form to a recurrence an = c1an−1 + c2an−2 + · · · + ckan−k looks like an = rn for some constant r. That would mean: rn = c1rn−1 + c2rn−2 + · · · + ckrn−k which we could rewrite as:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-73
SLIDE 73

Characteristic equation

Let’s suppose that the closed form to a recurrence an = c1an−1 + c2an−2 + · · · + ckan−k looks like an = rn for some constant r. That would mean: rn = c1rn−1 + c2rn−2 + · · · + ckrn−k which we could rewrite as: rn − c1rn−1 − c2rn−2 − · · · − ckrn−k = 0

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-74
SLIDE 74

Characteristic equation

Let’s suppose that the closed form to a recurrence an = c1an−1 + c2an−2 + · · · + ckan−k looks like an = rn for some constant r. That would mean: rn = c1rn−1 + c2rn−2 + · · · + ckrn−k which we could rewrite as: rn − c1rn−1 − c2rn−2 − · · · − ckrn−k = 0 and then we could divide both sides by rn−k to get:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-75
SLIDE 75

Characteristic equation

Let’s suppose that the closed form to a recurrence an = c1an−1 + c2an−2 + · · · + ckan−k looks like an = rn for some constant r. That would mean: rn = c1rn−1 + c2rn−2 + · · · + ckrn−k which we could rewrite as: rn − c1rn−1 − c2rn−2 − · · · − ckrn−k = 0 and then we could divide both sides by rn−k to get: rk − c1rk−1 − c2rk−2 − · · · − ck = 0 This is the characteristic equation of the recurrence.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-76
SLIDE 76

A helpful theorem

Suppose we have the characteristic equation rk − c1rk−1 − c2rk−2 − · · · − ck = 0 for the recurrence an = c1an−1 + c2an−2 + · · · + ckan−k and there are solutions r1, r2, . . . rm to the characteristic equation. Then, an = α1rn

1 + α2rn 2 + · · · + αmrn m satisfies the recurrence.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-77
SLIDE 77

Using this theorem

Recall the Fibonacci recurrence: f0 = f1 = 1 fn = fn−1 + fn−2

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-78
SLIDE 78

Using this theorem

Recall the Fibonacci recurrence: f0 = f1 = 1 fn = fn−1 + fn−2 The characteristic equation is:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-79
SLIDE 79

Using this theorem

Recall the Fibonacci recurrence: f0 = f1 = 1 fn = fn−1 + fn−2 The characteristic equation is: r2 − r − 1 = 0. Using the quadratic formula we get: r = 1 ±

  • (−1)2 − 4(1)(−1)

2 = 1 ± √ 5 2

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-80
SLIDE 80

Solving the Fibonacci recurrence

Thus, we know that fn = α1

  • 1 +

√ 5 2 n + α2

  • 1 −

√ 5 2 n

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-81
SLIDE 81

Solving the Fibonacci recurrence

Thus, we know that fn = α1

  • 1 +

√ 5 2 n + α2

  • 1 −

√ 5 2 n What to do next?

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-82
SLIDE 82

Solving the Fibonacci recurrence

Thus, we know that fn = α1

  • 1 +

√ 5 2 n + α2

  • 1 −

√ 5 2 n What to do next? Notice that we haven’t used our initial conditions: those will help us solve for α1 and α2.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-83
SLIDE 83

Solving the Fibonacci recurrence

Thus, we know that fn = α1

  • 1 +

√ 5 2 n + α2

  • 1 −

√ 5 2 n What to do next? Notice that we haven’t used our initial conditions: those will help us solve for α1 and α2. f0 = α1 + α2 = 0 which means that α2 = −α1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-84
SLIDE 84

Using the second base case

We know: f1 = α1

  • 1 +

√ 5 2

  • + α2
  • 1 −

√ 5 2

  • = 1

but we also know that α2 = −α1 from the previous page.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-85
SLIDE 85

Using the second base case

We know: f1 = α1

  • 1 +

√ 5 2

  • + α2
  • 1 −

√ 5 2

  • = 1

but we also know that α2 = −α1 from the previous page. So, we have α1

  • 1 +

√ 5 2

  • − α1
  • 1 −

√ 5 2

  • = 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-86
SLIDE 86

Using the second base case

We know: f1 = α1

  • 1 +

√ 5 2

  • + α2
  • 1 −

√ 5 2

  • = 1

but we also know that α2 = −α1 from the previous page. So, we have α1

  • 1 +

√ 5 2

  • − α1
  • 1 −

√ 5 2

  • = 1

which implies

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-87
SLIDE 87

Using the second base case

We know: f1 = α1

  • 1 +

√ 5 2

  • + α2
  • 1 −

√ 5 2

  • = 1

but we also know that α2 = −α1 from the previous page. So, we have α1

  • 1 +

√ 5 2

  • − α1
  • 1 −

√ 5 2

  • = 1

which implies α1

  • 1 +

√ 5 2 − 1 − √ 5 2

  • = 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-88
SLIDE 88

Using the second base case

We know: f1 = α1

  • 1 +

√ 5 2

  • + α2
  • 1 −

√ 5 2

  • = 1

but we also know that α2 = −α1 from the previous page. So, we have α1

  • 1 +

√ 5 2

  • − α1
  • 1 −

√ 5 2

  • = 1

which implies α1

  • 1 +

√ 5 2 − 1 − √ 5 2

  • = 1

and so α

  • 2

√ 5 2

  • = 1, which implies α1 =

1 √ 5.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-89
SLIDE 89

Solution

Thus, the Fibonacci sequence has closed form: fn = 1 √ 5

  • 1 +

√ 5 2 n − 1 √ 5

  • 1 −

√ 5 2 n

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-90
SLIDE 90

Golden ratio

Notice that if we have a and b satisfying: a + b b = a b

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-91
SLIDE 91

Golden ratio

Notice that if we have a and b satisfying: a + b b = a b then a

b = ϕ, where

ϕ = 1 + √ 5 2 .

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-92
SLIDE 92

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-93
SLIDE 93

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-94
SLIDE 94

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is: r2 − 2r − 1 = 0

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-95
SLIDE 95

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is: r2 − 2r − 1 = 0 which you can solve by factoring to get

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-96
SLIDE 96

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is: r2 − 2r − 1 = 0 which you can solve by factoring to get (r − 1)2 = 0.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-97
SLIDE 97

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is: r2 − 2r − 1 = 0 which you can solve by factoring to get (r − 1)2 = 0. Thus, r = 1 is a solution.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-98
SLIDE 98

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is: r2 − 2r − 1 = 0 which you can solve by factoring to get (r − 1)2 = 0. Thus, r = 1 is a solution. Problem: an = α1(1)n + α2(1)n for FIXED α1 and α2 has no solution!

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-99
SLIDE 99

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is: r2 − 2r − 1 = 0 which you can solve by factoring to get (r − 1)2 = 0. Thus, r = 1 is a solution. Problem: an = α1(1)n + α2(1)n for FIXED α1 and α2 has no solution! Fortunately, we can augment our theorem:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-100
SLIDE 100

Theorem isn’t exact enough yet

Recall: an = 2an−1 + an−2 with a0 = 0 and a1 = 5. The characteristic polynomial is: r2 − 2r − 1 = 0 which you can solve by factoring to get (r − 1)2 = 0. Thus, r = 1 is a solution. Problem: an = α1(1)n + α2(1)n for FIXED α1 and α2 has no solution! Fortunately, we can augment our theorem: If there is a root ri with multiplicity m + 1 (i.e., (r − ri)m+1 is a factor), then rn

i , nrn i , . . . nmrn i

are all solutions of the recurrence.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-101
SLIDE 101

Using this updated theorem

Since (r − 1)2 = r2 − 2r − 1, in our recurrence, r = 1 has multiplicity 2.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-102
SLIDE 102

Using this updated theorem

Since (r − 1)2 = r2 − 2r − 1, in our recurrence, r = 1 has multiplicity 2. Thus, we know that an = α101n + α11n1n which means an = α10 + α11n and we know a0 = 0, so α10 = 0.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-103
SLIDE 103

Using this updated theorem

Since (r − 1)2 = r2 − 2r − 1, in our recurrence, r = 1 has multiplicity 2. Thus, we know that an = α101n + α11n1n which means an = α10 + α11n and we know a0 = 0, so α10 = 0. Also, we know a1 = 5 and so 5 = α11. Thus, an = 5n, as we proved earlier.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-104
SLIDE 104

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-105
SLIDE 105

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous!

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-106
SLIDE 106

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-107
SLIDE 107

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn. For this recurrence, hn = 2hn−1 is easily seen to be hn = 2n since the characteristic equation is

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-108
SLIDE 108

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn. For this recurrence, hn = 2hn−1 is easily seen to be hn = 2n since the characteristic equation is r = 2.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-109
SLIDE 109

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn. For this recurrence, hn = 2hn−1 is easily seen to be hn = 2n since the characteristic equation is r = 2. The constant term is 1 in an, so we guess that bn = c for some constant c.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-110
SLIDE 110

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn. For this recurrence, hn = 2hn−1 is easily seen to be hn = 2n since the characteristic equation is r = 2. The constant term is 1 in an, so we guess that bn = c for some constant c. Therefore, bn = 2bn−1 + 1 and if bn = c, we get

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-111
SLIDE 111

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn. For this recurrence, hn = 2hn−1 is easily seen to be hn = 2n since the characteristic equation is r = 2. The constant term is 1 in an, so we guess that bn = c for some constant c. Therefore, bn = 2bn−1 + 1 and if bn = c, we get c = 2c + 1

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-112
SLIDE 112

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn. For this recurrence, hn = 2hn−1 is easily seen to be hn = 2n since the characteristic equation is r = 2. The constant term is 1 in an, so we guess that bn = c for some constant c. Therefore, bn = 2bn−1 + 1 and if bn = c, we get c = 2c + 1 which gives c = −1,

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-113
SLIDE 113

A few words on non-homogeneous linear recurrences

We have seen an = 2an−1 + 1 with (a0 = 1) has closed form an = 2n+1 − 1. But, this is non-homogeneous! Trick: Solve the homogeneous equation, hn, and then try to figure

  • ut what the additional term is, in terms of n, as bn, then

an = hn + bn. For this recurrence, hn = 2hn−1 is easily seen to be hn = 2n since the characteristic equation is r = 2. The constant term is 1 in an, so we guess that bn = c for some constant c. Therefore, bn = 2bn−1 + 1 and if bn = c, we get c = 2c + 1 which gives c = −1, and thus (after verifying) our recurrence is an = 2n − 1.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

slide-114
SLIDE 114

Work on problems!

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING