CSE 421 Section 6
Midterm Review
Reminders
Midterm Exam: Monday November 3 @ ECE 105 @ 5.30pm (actual exam: 100 mins)
Stable Matching
Problem 1 – Practice a Reduction
BasicStableMatching
Input: A set of k horses and k riders. Each horse has a preference list of all k riders, and each rider has a preference list of all k horses.
Output: A stable matching among the k horses and k riders.
Problem 1 – Practice a Reduction
Work through this problem with the people around you, and then we’ll go over it together!
Problem 1 – Practice a Reduction
Problem 1 – Practice a Reduction
Create an instance where each horse has 3 copies (one per ride) and extra “fake” riders to balance the sides. Modify the preference list to represent what the agents want in the problem.
Problem 1 – Practice a Reduction
Problem 1 – Practice a Reduction
Problem 1 – Practice a Reduction
Problem 1 – Practice a Reduction
The Basic algorithm doesn’t produce blocking pairs, so we won’t either (once we delete the dummies).
Problem 1 – Practice a Reduction
Problem 1 – Practice a Reduction
Problem 1 – Practice a Reduction
Problem 1 – Practice a Reduction
Graph Algorithms
Problem 2 – Running Out of Rooms
Problem 2 – Running Out of Rooms
Swati [123 Fake St., 200 State St.]
Ewin [200 State St., 1000 Main St.]
Xin [null, 123 Fake St.]
Victor [567 Broadway, null]
Output: Easy Movement and [Victor, Ewin, Swati, Xin].
There are other valid lists to return here, you only need to give one.
Swati [123 Fake St., 200 State St.]
Ewin [200 State St., 1000 Main St.]
Xin [1000 Main St, 123 Fake St.]
Victor [567 Broadway, null]
Output: No Easy Movement and
[Swati, Ewin, Xin].
There is no easy movement in this example, because none of Swati, Ewin, and Xin can move first – they each need one of the others to go first.
Problem 2 – Running Out of Rooms
Work through this problem with the people around you, and then we’ll go over it together!
Problem 2 – Running Out of Rooms
Problem 2 – Running Out of Rooms
Problem 2 – Running Out of Rooms
Problem 2 – Running Out of Rooms
Problem 2 – Running Out of Rooms
Problem 2 – Running Out of Rooms
Greedy Algorithms
Problem 3 – Interval Covering
Work through this problem with the people around you, and then we’ll go over it together!
Problem 3 – Interval Covering
Key Idea Take the next interval that helps, i.e. that covers a new point; among all such intervals (if more than
one) take one that goes the farthest right.
Problem 3 – Interval Covering
Key Idea Take the next interval that helps, i.e. that covers a new point; among all such intervals (if more than
one) take one that goes the farthest right.
function IntervalCovering(𝒳)
𝒴 ← ∅
Sort 𝒳 by increasing start, breaking ties by decreasing end.
Let y be the start time of the first element of 𝒳
while 𝒳 ≠ ∅ do
Let I = [s, e] be the element remaining in 𝒳, with latest end time among those starting y or earlier.
𝒴 ← 𝒴 ∪ {I}
Delete all elements of X with endtime e or earlier
y ← first uncovered point past e
Problem 3 – Interval Covering
Correctness:
Problem 3 – Interval Covering
Problem 3 – Interval Covering
Problem 3 – Interval Covering
Running Time:
Problem 3 – Interval Covering
Divide and Conquer
Problem 4 – on handout
Dynamic Programming
Problem 5 – �Longest Palindromic Subsequence
Problem 5.1 – Write the Dynamic Program
Work through this problem with the people around you, and then we’ll go over it together!
Problem 5.1 – Write the Dynamic Program
Problem 5.1 – Write the Dynamic Program
Let OPT(i, j) be the length of the longest palindromic subsequence among indices i, ..., j.
Problem 5.1 – Write the Dynamic Program
Problem 5.1 – Write the Dynamic Program
Problem 5.1 – Write the Dynamic Program
Problem 5.1 – Write the Dynamic Program
Problem 5.1 – Write the Dynamic Program
Problem 5.1 – Write the Dynamic Program
Problem 5.2 – Analyze the Dynamic Program
Work through this problem with the people around you, and then we’ll go over it together!
Problem 5.2 – Analyze the Dynamic Program
Problem 5.2 – Analyze the Dynamic Program
Problem 5.2 – Analyze the Dynamic Program
Problem 5.2 – Analyze the Dynamic Program
Problem 5.2 – Analyze the Dynamic Program
Problem 5.2 – Analyze the Dynamic Program
That’s All, Folks!
Thanks for coming to section this week!
Any questions?