Tut - 5 Dynamic Programming
Tut - 5 Dynamic Programming
1. Consider the Weighted Vertex Cover problem where given a graph G = (V, E) of order n, a positive
and a weight function w : V → R+ , the task is to decide whether there exists a S ⊆ V
integer k, P
such that v ∈S w (v ) ≤ k and S ∩ {u, v } =
̸ ∅ for every {u, v } ∈ E(G).
Design a dynamic programming algorithm to solve Weighted Vertex Cover on trees.
2. Consider the following scheduling problem: there are n jobs to be scheduled on a single machine,
where each job j has a processing time pj , a weight wj , and a due date dj , j = 1, . . . , n. The objective
is to schedule the jobs so as to maximise the total weight of jobs that complete by their due date.
First prove that there always exist an optimal schedule in which all on-time jobs complete before all
late jobs, and the on-time jobs complete in the earliest due date order. Use this structural P result to
show how to solve this problem using Dynamic Programming in O(nW ) time, where W = j wj .
3. Given a m × n grid filled with non-negative numbers, find a path from the top left to bottom right,
which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
Example:
4. Given two strings a and b which contain "wild-card" characters " ∗ " and "?", we want to match
the strings in a way, where if one string contains " ∗ ", it can be matched with any character or
number of characters in the other string. On the other hand, if one string has the character "?", it
can be matched with any one character of the other string. Given two strings of length m and n,
design an algorithm that checks whether the strings match.
5. Given a set S of positive integers, determine if it can be partitioned into three disjoint subsets that
all have the same sum, and they cover S.
6. Given two text strings A of length n and B of length m, you want to transform A into B with a
minimum number of operations of the following types: delete a character from A, insert a character
into A, or change some character in A into a new character. The minimal number of such operations
required to transform A into B is called the edit distance between A and B.
7. Given a rod of length n inches and an array of prices that includes prices of all pieces of size smaller
1
than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces. We
are mainly given a price array such that the size of the price array is same as rod length and pr i ce[i ]
represents price of length i + 1.
8. There are n stairs, a person standing at the bottom wants to climb stairs to reach the nth stair. The
person can climb either 1 stair or 2 stairs at a time, the task is to count the number of ways that a
person can reach at the top.