CSE 421 Section 5
Dynamic Programming
Administrivia
Announcements & Reminders
Writing a Dynamic Programming Algo
Dynamic Programming
The Strategy (SLIGHTLY DIFFERENT FOR DP)
Dynamic Programming Process (from lecture)
This is what we’ll do in parts 3 and 4 of our strategy:
Problem 1 – Lots of fun, with a normal sleep schedule
1. Read and Understand the Problem
Problem 1.1 – Fun & Sleep
Problem 1.1 – Fun & Sleep
Problem 1.1 – Fun & Sleep
“consecutive” means in a row
“maximize the sum of the happinesses” is semi-technical?
Problem 1.1 – Fun & Sleep
“consecutive” means in a row
“maximize the sum of the happinesses” is semi-technical?
int[]
Problem 1.1 – Fun & Sleep
int[]
int (the maximum sum of happinesses)
“consecutive” means in a row
“maximize the sum of the happinesses” is semi-technical?
2. Generate Examples
Good Examples Help!
Problem 1.2 – Fun & Sleep
Generate two examples with their associated outputs. Put some effort into these! The more different from each other they are, the more likely you are to catch mistakes later.
Work through generating some examples, and then we’ll go over it together!
Problem 1.2 – Fun & Sleep
Generate two examples with their associated outputs. Put some effort into these! The more different from each other they are, the more likely you are to catch mistakes later.
Problem 1.2 – Fun & Sleep
Generate two examples with their associated outputs. Put some effort into these! The more different from each other they are, the more likely you are to catch mistakes later.
3. Write the Dynamic Program
Problem 1.3 – Fun & Sleep
Start brainstorming some answers to these questions.
Problem 1.3 – Fun & Sleep
First, let’s take some time to brainstorm about what the recurrence could be. What is our OPT finding? How many parameters do we need to calculate it? What are those parameters for?
Problem 1.3 – Fun & Sleep
Problem 1.3 – Fun & Sleep
Problem 1.3 – Fun & Sleep
Problem 1.3 – Fun & Sleep
Problem 1.3 – Fun & Sleep
Problem 1.3 – Fun & Sleep
Problem 1.3 – Fun & Sleep
Problem 1.3 – Fun & Sleep
Give a brief justification for why your recurrence is correct. You do not need a formal inductive proof, but your intuition will likely resemble one.
4. Analyze the Dynamic Program
Problem 1.4 – Fun & Sleep
Start brainstorming some answers to these questions.
Problem 1.4 – Fun & Sleep
Problem 1.4 – Fun & Sleep
Problem 1.4 – Fun & Sleep
Problem 1.4 – Fun & Sleep
Problem 2: �Longest Increasing Subsequence
Problem 2 – Longest Increasing Subsequence
Given an array A, find the longest sub-array of A whose elements are in increasing order.
As an example, [10, −2, 5, 0, 3, 11, 8] has a longest increasing subsequence of 4 elements: [−2, 0, 3, 8]
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.1 – Write the Dynamic Program
Problem 2.2 – Analyze the Dynamic Program
Start brainstorming some answers to these questions.
Problem 2.2 – Analyze the Dynamic Program
Problem 2.2 – Analyze the Dynamic Program
Problem 2.2 – Analyze the Dynamic Program
Problem 2.2 – Analyze the Dynamic Program
Problem 2.2 – Analyze the Dynamic Program
Problem 2.2 – Analyze the Dynamic Program
That’s All, Folks!
Thanks for coming to section this week!
Any questions?