You are on page 1of 3

COT 5405 Analysis of Algorithms, Fall 2008.

Homework 3
Due Thursday, November 13 2008, 3:30pm.
Notes Turn-in questions 1-6 only. The TA will be available in CSE E309, at the time the homework is due. You may also hand the homework to Prof. Ranka in class. No late submissions. To force you to write succinctly, we have enforced page limits. These are noted in front of each question. Answer each question on a fresh page. Whenever you are writing a dynamic programming solutions, you must write it down in the following format: (a) Description (in words) of function being computed (So, for example, with TSP this would be:Let g(i, S) be the length of shortest path starting at vertex i, going through all vertices in S and terminating at vertex 1.) (b) Recursive denition of function (c) Base case for the above recursive function (d) Description of table construction informally in a paragraph rst, followed by pseudocode, if necessary. We will peruse your pseudocode only if your English description is not clear. (e) Complexity. Write your name on the top right hand corner of your homework. Be sure to write your last name as the last word in your name. Please write legibly.

1. [1 page] A problem in Statistics is to nd the most probable state transition for a Markov chain. Essentially, there are k states we denote by s1 , , sk . At every step, a transition between states is made with a known (given) probability. In particular, the transition between states si and sj is made with probability pij ; this probability is dened for i = j as well, when the system stays in the same state. Your task is to nd the sequence of states of length n that is the most probable (the sequence can contain the same state multiple times). Since the model is assumed to be a Markov chain, the probability of a sequence of states is simply the product of probabilities of transitioning between consecutive states in the sequence. In summary, your task is to nd the sequence of states of length n with the property that the products of probabilities of transition between the consecutive states (probabilities which are given) is maximized.

2. [1 page] A company is planning a party for its employees. A fun rating is assigned to every employee. The employees are organized into a strict hierarchy, i.e. a tree rooted the president. There is one restriction, though, on the guest list to the party: an employee and his/her immediate supervisor (parent in the tree) cannot both attend the party. You wish to prepare a guest list for the party that maximizes the sum of fun ratings of the guests. Show that greedily choosing guests according to fun rating, will not work. Then, formulate a dynamic programming solution. 3. [1 page] Design a dynamic programming formulation for Problem 4 of Exam 2 (which is reproduced below). You are given a sequence of integers a1 , . . . , an , where 1 ai m, m being a xed integer. You are asked to produce another sequence, b1 , . . . , bn , for which the following conditions hold: (a) 1 bi m (b) i ai = bi (c) The number of is, 1 i n, for which bi = bi+1 , is minimized. Example 1: Let m = 5 and the sequence a be (3,5,2,4,1,4,1,5). Then for the sequence b = (2,2,1,2,2,2,2,2) the rst two conditions hold and we have bi = bi+1 twice: b3 = b4 and b2 = b3 . However the last condition does not hold for b. Example 2: For the same a, let b be the sequence (2,2,3,3,3,3,3,3). Now we have bi = bi+1 for only one number, and all three conditions hold fo r this sequence. 4. [1 page] Consider a 2-D map with a horizontal river passing through its center. There are n cities on the southern bank with x-coordinates a1 , . . . , an and n cities on the northern bank with x-coordinates b1 . . . , bn (Note that the co-ordinates are not necessarily sorted). You want to connect as many northsouth 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 dynamic programming solution for this problem.
1 5. [ 2 page] For a given a string X, a substring inversion is dened to be an edit operation that replaces the R substring Xij = xi xi+1 xi+2 xj1 xj with its inversion, or reversal Xij = xj xj1 xi+1 xi . Two such substring inversions are said to be independent if the two substrings (that are about to be reversed) do not overlap (i.e. are disjoint in the original string). For example, in t he string VENKAT the substrings VEN and KAT are independent whereas VENK and NKAT are not. Observe that this operation does not alter the lengths of the strings.

Given two strings X & Y , each of length n, write down the recurrence relation (you need not give the complexity of your algorithm) using which one can write an algorithm to determine the minimum number of independent substring inversions needed to convert X into Y (or if it is impossible t o do so). For example, in the given example, X can be transformed into Y using only 3 independent substring inversions. 6. [1 page] The SubsetSum problem takes as input a set X = {k1 , k2 , ..., kn } of integers and another integer K. The problem is to check if there exists a subset X of X whose elements sum to K. for example, if X = {5, 3, 11, 8, 2} and K = 16 then the answer is YES since the subset X = {5, 11} has a sum of 16. Design a dynamic programming solution whose run time is O(nK) .

7. The problem of OBST (Optimal Binary Search Tree) is as follows: You are given a set of identiers along with their search probabilities. The task is to form a binary search tree, which minimizes the expected number of comparisons. To be more precise: Let the given identiers a1 , ..., an be ordered ascendingly, let their given search probabilities be p1 , ..., pn . Also let q0 , ..., qn be the given, where qi is the probability that an identier not in the tree but between ai and ai+1 (q0 is the probability that the identier being search for is less than a1 ) . Design a dynamic programming solution that produces the optimal binary search tree given these inputs. 8. Consider a variant of the 0/1 Knapsack problem in which you have innite copies of each item. Formally, there are n types of items, with each item i having an integer weight wi and a value vi . You have a knapsack with capacity W , which you have to ll up with whole items with maximum value. You are allowed to add multiple items of the same type to the knapsack. Design a dynamic programming solution for the problem.

You might also like