Lecture 36 on: 11/29/10

(Guest post by Anthony Rocco)

In Lect. 36 Prof. Rudra  introduced to us a new algorithmic technique known as dynamic programming. Dynamic programming is similar to divide and conquer in the sense that it uses recursion in order to achieve its objective. However, dynamic programming is more advantageous in respect to how it goes about solving its sub-problems. That is, dynamic programming algorithms solve their sub-problems in a “smarter” fashion than their divide and conquer counterpart. One such method of accomplishing this is a more adept usage of memory.

The example of this that was given in class is:

D&C Approach:   pow(a,n)

return pow(a,n/2)*pow(a,n/2)

Dynamic Programming Approach:   pow (a,n)

t=pow(a,n/2)
return t*t

Following this example,  we took a look at the weighted interval scheduling problem with the intent to implement a dynamic programming algorithm to provide us with an optimal schedule.

Input: n intervals [si,fi) 1<=i<=n
Output: A schedule S{1,……}
s.t. For All i != j element of S i and j have no conflict
Objective: Max( ∑i∈ S [ Vi ])

Assumption: Jobs are sorted
|———–|                v6=1
|—————–|                          v5=30
|——|                        v4=5
|—————–|                          v3=1
|—–|                                    v2=10
|———–|                                     v1=2
|—–1—–2—–3—–4—–5—–|

Reasoning about the Optimal Solution:
Let O be an optimal solution

Case 1: 6 is an element of O
Intervals {3,4,5} are not in O since they conflict with 6
O{6} U Optimal soln on {1,2}

Case 2: 6 is ! an element of O
O is a schedule on {1,…,5}
and O is an optimal schedule {1,…,5}

=> Optimal will choose the better option

Definition: p(j)= largest value of i that doesn’t conflict with j or largest i s.t. fi<sj
=0 if no such i

Lets called the Optimal Solution for {i,….,j} Oj, who’s value will be denoted by the function Opt(j). Then, we have two cases:

Case 1: jOj => Oj={j} U Op(j)

Case2: j Oj => Oj=Oj-1

and, Opt(j) = max(vj+Opt(p(j)),Opt(j-1))                 **Opt(0)=0**

We then have the algorithm:

Compute-Opt(j)
If j=0
return 0

else     max(vj+Opt(p(j)),Opt(j-1))


This entry was posted in fall 2010. Bookmark the permalink.

2 Responses to Lecture 36 on: 11/29/10

  1. amrocco says:

    I had all the lines spaced correctly in the chart of the interval scheduling, but it must have moved them back to the margin when I published the post, sorry!

  2. Pingback: Lect 36: Dynamic Programming « Introduction to Algorithm Analysis and Design

Leave a comment