Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Topics Recursion sections 8.1 – 8.2. 2 Recursion A recursively defined sequence –First, certain initial values are specified –Later terms of the sequence.

Similar presentations


Presentation on theme: "1 Topics Recursion sections 8.1 – 8.2. 2 Recursion A recursively defined sequence –First, certain initial values are specified –Later terms of the sequence."— Presentation transcript:

1 1 Topics Recursion sections 8.1 – 8.2

2 2 Recursion A recursively defined sequence –First, certain initial values are specified –Later terms of the sequence are defined by relating them to earlier terms Example a 1 = 1, a 2 = 1, and a k = a k-2 + a k-1,  k > 2 Write down the first ten terms of that sequence. That’s the Fibonacci sequence! (p.464) See also http://en.wikipedia.org/wiki/Fibonacci_numberhttp://en.wikipedia.org/wiki/Fibonacci_number

3 3 Recursion Exercise: Define the sum of the first k natural numbers as a recurrence sequence. a 1 = 1, a k = a k-1 + k,  k > 1. Exercise: Given the above sequence a, determine whether the following statement is true or false.  k > 1, a k+1 = a k + k + 1. Q: Can sequence a be defined as follows? a 1 = 1, a k+1 = a k + k + 1,  k > 1.

4 4 More Exercises Define the sum of the squares of the first k natural numbers as a recurrence sequence. Write down the first 10 terms of the following sequence. b 1 = 1, b k = 2b k-1,  k > 1. What’s missing in the following recurrence sequence definition? b k = b k-1 + 2k,  k > 0. Write down the first 10 terms of the following sequence. b 1 = 2, b k = 2b k-1,  k > 1.

5 5 8.2: Solving recurrence relations A solution to a recurrence relation is an explicit formula for that sequence. The most basic method for finding a solution for a recursively defined sequence is iteration. –Given a sequence b 0, b 1, b 2, …and initial conditions, start from the initial conditions; –Then, calculate the successive terms of the sequence until you see a particular pattern developing; –At that point, you guess an explicit formula. Examples: 8.2.1

6 6 Solving recurrence relations (cont.) k akak 01 11+2 21+2+2 31+2+2+2 … n1+? Examples: 8.2.1 a 0 = 1 a k = a k-1 + 2,,  k > 0

7 7 Solving recurrence relations (cont.) k akak 01 11+r 2 3 4 … n? Examples: a 0 = 1 a 1 = r a k = a k-1 + r k,,  k > 1 Ans: p.480

8 8 Exercises p.485: 1, 2, 3, 4 p.486: 23, 25

9 9 Questions?


Download ppt "1 Topics Recursion sections 8.1 – 8.2. 2 Recursion A recursively defined sequence –First, certain initial values are specified –Later terms of the sequence."

Similar presentations


Ads by Google