0% found this document useful (0 votes)
54 views3 pages

Practice Sheet 4 2016 Practice Sheet 4 2016

The document describes 5 problems related to algorithms and dynamic programming: 1) A weighted job scheduling problem to find the most profitable set of non-overlapping jobs. 2) Finding the longest monotonically increasing subsequence in a given sequence. 3) Finding the maximum number of non-crossing bridges between cities on opposite banks of a river. 4) Computing the edit distance between two strings with minimum character operations. 5) Finding the optimal parenthesization for matrix chain multiplication to minimize operations.

Uploaded by

Shubham Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Practice Sheet 4 2016 Practice Sheet 4 2016

The document describes 5 problems related to algorithms and dynamic programming: 1) A weighted job scheduling problem to find the most profitable set of non-overlapping jobs. 2) Finding the longest monotonically increasing subsequence in a given sequence. 3) Finding the maximum number of non-crossing bridges between cities on opposite banks of a river. 4) Computing the edit distance between two strings with minimum character operations. 5) Finding the optimal parenthesization for matrix chain multiplication to minimize operations.

Uploaded by

Shubham Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

lOMoARcPSD|9106035

Practice sheet 4 2016

Data Structure and Algorithm (Indian Institute of Technology Kanpur)

StuDocu is not sponsored or endorsed by any college or university


Downloaded by Subham Kumar ([email protected])
lOMoARcPSD|9106035

Design and Analysis of Algorithms

Practice-sheet 4 : Dynamic Programming

1. (Weighted job scheduling problem)


There are n jobs : hJ1 , . . . , Jn i and a single server. Job Ji has a start time si and
finish time fi . The server can execute only one job at a time. Unfortunately, there is
overlap between the time spans of various jobs, and so we can not execute all the jobs
on the server. Each job has also a profit associated with it which is obtained if that
job is executed on the server. Let pi denote the profit associated with job Ji . Give
a counter-example to show that the greedy strategy “select the earliest finish time”
won’t work here. Design a polynomial time algorithm to find a subset of jobs that
can be executed on the server such that the profit obtained is maximum.

2. (Monotonically increasing subsequence)


Given a sequence A = a1 , . . . , an , a subsequence ai1 , ai2 , . . . , aik is said to be mono-
tonically increasing if aij < aij+1 for all 1 ≤ j < k. Design an O(n2 ) time algorithm
to compute the longest monotonically increasing subsequence of sequence A.

3. (Bridges across a river)


Consider a 2-D map with a horizontal river passing through its center. There are n
cities on the southern bank with x-coordinates a(1)...a(n) and n cities on the north-
ern bank with x-coordinates b(1)...b(n). Note that there is no order among a(i)’s.
Similarly, you can’t assume any order among b(i)’s. You want to connect as many
north-south pairs of cities as possible with bridges such that no two bridges cross.
When connecting cities, you can only connect city i on the northern bank to city i
on the southern bank. Design a polynomial time algorithm to compute the maximum
number of non-crossing bridges that can be built.

4. (Edit Distance)
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. Design a polynomial time algorithm to compute edit
distance between A and B.

5. (Matrix chain multiplication)


There is a sequence of matrices M1 , M2 , . . . , Mn storing numbers. For each 1 < i ≤ n,
the number of rows of Mi is identical to the number of columns of Mi−1 . So the
product M1 × M2 × . . . Mn is well defined. We also know that matrix multiplication
is associative. That is, (M1 × M2 ) × M3 = M1 × (M2 × M3 ). However, the number of
arithmetic operations required may vary in these two possible ways. For example, let
M1 be 10 × 100, M2 be 100 × 5, and M3 be 5 × 50.

1
Downloaded by Subham Kumar ([email protected])
lOMoARcPSD|9106035

• If we multiply according to ((M1 × M2 ) × M3 ), we perform 10 · 100 · 5 = 5000


multiplication operations to compute the 10 × 5 matrix (M1 × M2 ) and then
10 · 5 · 50 multiplication operations to multiply this matrix with M3 . So a total
of 7500 multiplication operations are carried out.
• If instead we multiply according to (M1 × (M2 × M3 )), we perform 100 · 5 · 50 =
25000 scalar multiplications to compute 100 × 50 matrix (M2 × M3 ) and then
another 10 · 100 · 50 = 50000 multiplication operation to multiply M1 by this
matrix. Hence a total of 75000 multiplication operations are carried out.

Our aim is to compute M1 × M2 × · · · × Mn using least number of multiplication


operations. Design an algorithm based on dynamic programming to solve this prob-
lem in polynomial time. Here is some additional explanation which should help you
understand the problem better.
The order in which we compute M1 × M2 × · · · × Mn is defined by parenthesizing the
expression of n matrices. For example, if n = 4, then there are the following 4 ways
to compute the product:

• (((M1 × M2 ) × M3 ) × M4 )
• ((M1 × M2 ) × (M3 × M4 ))
• (M1 × ((M2 × M3 ) × M4 ))
• (M1 × (M2 × (M3 × M4 )))

The number of ways to parenthesize the expression is exponential (it is catalan num-
ber). Of course, we can not afford to try out each possible way to multiply the n
matrices.
Hint: Consider that parenthesized expression that corresponds to the least number
of multiplication operations. If you multiply the matrices according to this parenthe-
sization, the number of matrices will reduce by 1 each time. Finally we will be left
with only 2 matrices. How do these last two matrices which are multiplied look like
? What can you infer from it ? Use it to come up with a recursive formulation.

2
Downloaded by Subham Kumar ([email protected])

You might also like