next up previous
Next: About this document ...

CS 1510 Midterm 1

Fall 1999



1.
(40 points) The first problem that we considered this semester was the following one:


INPUT: A collection of intervals $C = \{(a_1, b_1), \ldots, (a_n, b_n) \}$ over the real line.

OUTPUT: A maximum cardinality collection of disjoint intervals.


We consider greedy algorithms for solving this problem that are of the following form:


1. Pick the interval I from the remaining intervals in C, and add I to the solution set S.

2. Remove I, and any intervals that overlap with I, from C.

3. If C is not yet empty, go to step 1.


One can get different greedy algorithms depending on how I is selected. For each of the following method of selecting I, prove or disprove the that resulting greedy algorithm correctly solves the problem.

(a)
Pick I to be the interval (ai, bi) that minimizes bi, that is, pick I to be the interval with the leftmost right endpoint. Ties may be broken arbitrarily.

(b)
Pick I to be the interval (ai, bi) that minimizes bi - ai, that is, pick I to be the shortest interval. Ties may be broken arbitrarily.

(c)
Pick I to be the interval (ai, bi) that intersects the least number of other intervals currently in C. Ties may be broken arbitrarily.

2.
(20 points) We consider the problem of computing the longest common subsequence of two sequences $A=a_1, \ldots, a_m$ and $B=b_1, \ldots, b_n$. Let T(i,j) be the length of the longest common subsequence of $a_1, \ldots, a_i$ and $b_1, \ldots, b_j$.

(a)
Write a recursive function to compute T(i, j) in the naive way. Don't forget the base case(s).

(b)
Show that if you implement this recursion directly in say the C programming language, that the program could use time that is exponential in n.

(c)
Write iterative array based code to compute T(m, n) that runs in O(n2) time.

(d)
Write code to actually find the longest common subsequence from your array.

3.
(20 points) Consider the following problem. The input to this problem consists three points s1, s2 and s3 in the Euclidean plane that represent the starting locations of three taxis and a list $r_1, r_2, \ldots, r_m$ of m requests, where each request is a point in the plane. These requests must be serviced in order, i.e. request r1 must be handled before request r2, which must be serviced before request r3, etc. If the taxi cabs are currently at points v1, v2 and v3, then in response to a request ri one of the three taxi cabs must move to point ri; If the first taxi moves then the taxi company incurs a cost of d(v1, ri), of the distance between v1 and ri, if the second taxi moves then the taxi company incurs a cost of d(v2, ri), the distance between v2 and ri, and if the third taxi moves then the taxi company incurs a cost of (v3, ri) the distance between v3 and ri, The taxi company's problem is to compute the cost of the cheapest schedule for handling these requests. Give an O(n3) time algorithm that solves this problem.

Note that this is identical to the taxi cab homework problem except that we now assume three taxis instead of two taxis.

4.
(20 points) Consider the following problem. The input to this problem of consists of a positive integer k, and a sequence $A = a_1, \ldots, a_n$ of integers. The output should be the longest k-slowly increasing subsequence of A. A sequence $B = b_1, \ldots, b_m$ is is k-slowly increasing if $b_{i+1} - k \le b_i < b_{i+1}$ for $1 \le i \le m-1$, that is, if B increases by some number between 1 and k on each step. Give an O(n2) time algorithm that solves this problem.




next up previous
Next: About this document ...
Kirk Pruhs
1999-11-04