Non-Homogeneous Recurrence Relations

Download Report

Transcript Non-Homogeneous Recurrence Relations

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
CS 312: Algorithm Analysis
Lecture #8: Non-Homogeneous
Recurrence Relations
Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick
Announcements
 HW #5: due now
 Start Project #2!
 Budget enough time
 Be sure to keep up in the required reading
listed on the schedule in Learning Suite
Convex Hull (Proj. #2)
Objectives
 Big Picture:
 Develop a method to analyze recursive divide and
conquer algorithms
 Work up to a proof of the Master Theorem
 Find specific solutions using initial conditions
 Understand how to solve
non-homogeneous, linear, recurrence relations
with constant coefficients
 Having geometric forcing functions
Example (cont.): Linear, Homogeneous
Recurrence Relation
General Solution: Linear
Combinations
Starting things off
 How many sequences does this recurrence relation describe?
 Here’s one:
 0, 1, 5, 19, …
 Here’s another:
 1, 2, 4, 18, …
 Notice: a different sequence for every initial condition.
 Question: can we find the closed form for the 𝑛th number 𝑡𝑛 in
a specific sequence?
 Given: 𝑡0 and 𝑡1
 Find: 𝑡𝑛 = some function of 𝑛 ← known as the “specific solution”
 Idea: Let’s start with the general solution
Finding the Specific Solution
Specific Solution: One point
Fibonacci in Closed Form!
Fundamental Theorem of Algebra
 For every polynomial of degree n, there
are exactly n roots.
 They may not be unique.
Roots of Multiplicity j
Roots of Multiplicity j
Roots of Multiplicity j
Example
CS 312: Algorithm Analysis
Remainder of Lecture #8:
Non-homogeneous Linear
Recurrence Relations
Non-Homogeneous, Linear
Recurrence Relations
𝑎0 𝑡𝑛 + 𝑎1 𝑡𝑛−1 + 𝑎2 𝑡𝑛−2 + … 𝑎𝑘 𝑡𝑛−𝑘 = 𝑓 𝑛
 Where:
𝑓 𝑛 ≠0
 𝑓 𝑛 = 𝑏𝑛 ⋅ 𝑝 𝑛
 Called a “geometric forcing function”
 𝑝 𝑛 is a polynomial of degree 𝑑
Non-Homogeneous Example
1. Substitute 𝑛 − 1 into ®:
2. Divide ® by 𝑏:
3. Subtract (2) from (1):
4. Simplify:
What do you notice about the problem now?
Example (Cont.)
Coincidence?
 Original Non-homogeneous recurrence:
 𝑡𝑛 − 3𝑡𝑛−1 = 4𝑛
 Reduced to a Homogeneous recurrence:
 𝑡𝑛 − 7𝑡𝑛−1 + 12𝑡𝑛−2 = 0
 General solution (to both):
 𝑡𝑛 = 𝑐1 3𝑛 + 𝑐2 4𝑛
 This pattern holds in general!
The Characteristic Equation Theorem:
𝑎0 𝑡𝑛 + 𝑎1 𝑡𝑛−1 + 𝑎2 𝑡𝑛−2 + ⋯ + 𝑎𝑘 𝑡𝑛−𝑘 = 𝑏 𝑛 ⋅ 𝑝 𝑛
(where 𝑝 𝑛 has degree 𝑑) has characteristic equation:
𝑎0 𝑟 𝑘 + 𝑎1 𝑟 𝑘−1 + ⋯ + 𝑎𝑘 𝑟 − 𝑏 𝑑+1 = 0
Note: 𝑏 is a root of multiplicity 𝑑 + 1
The Characteristic Equation Theorem:
𝑎0 𝑡𝑛 + 𝑎1 𝑡𝑛−1 + 𝑎2 𝑡𝑛−2 + ⋯ + 𝑎𝑘 𝑡𝑛−𝑘 = 𝑏 𝑛 ⋅ 𝑝 𝑛
(where 𝑝 𝑛 has degree 𝑑) has characteristic equation:
𝑎0 𝑟 𝑘 + 𝑎1 𝑟 𝑘−1 + ⋯ + 𝑎𝑘 𝑟 − 𝑏 𝑑+1 = 0
Note: 𝑏 is a root of multiplicity 𝑑 + 1
Initial Conditions
Example (cont.)
Example (cont.)
Towers of Hanoi Revisited
Exercise on HW #6
Assignment
 Read: Recurrence Relations Notes
 HW #6:
 Part II Exercises (Section 2.2)
 Towers of Hanoi using method of recurrence
relations.
Extra Slides
Possible DC Solution: Step 1


Given set of n points
Divide into two subsets



L containing the leftmost points
R containing the rightmost points
All points with same x coordinate


Assign to the same subset
Even if this makes the division not exactly
into halves
Possible DC Solution: Step 2
Compute the convex hulls of L and R
recursively
Possible DC Solution: Step 3
 Combine the left hull CH(L) and the right hull CH(R):
 Find the two edges known as the upper and lower common
tangents (shown in red)
 Common tangent: a line segment in the exterior of both
polygons intersecting each polygon at a single vertex or a single
edge.
 The line containing the common tangent does not intersect the
interior of either polygon
Possible DC Solution: Tips
 Find the upper common tangent:
 Scan around the left hull in a clockwise direction and around the
right hull in a counter-clockwise direction
 Come up with the details of finding the common tangents
– hints available in the guidelines document
 The tangents divide each hull into two pieces
 Delete the right edges belonging to the left hull and the
left edges belonging to the right hull