Sunteți pe pagina 1din 2

Algorithms: CSE 202 — Additional problems along the lines of

homework II problems

Problem 1: Longest increasing subsequence


The input is a sequence of numbers a1 , . . . , an . A subsequence is any subset of these numbers
taken in order. An increasing subsequence is one in which the numbers are getting larger. The task
is to find the length of the longest increasing subsequence.

Problem 2: Book packing


Consider the problem of storing n books on shelves in a library. The order of the books is fixed by
the cataloging system and so cannot be rearranged. Therefore, we can speak of a book bi , where
1 ≤ i ≤ n, that has a thickness ti and height hi . The length of each bookshelf at this library is L.

1. Suppose all the books have the same height h and the shelves are all separated by a distance
of greater than h, so any book fits on any shelf. The greedy algorithm would fill the first shelf
with as many books as we can until we get the smallest i such that bi does not fit, and then
repeat with the subsequent shelves. Show that the greedy algorithm always finds the optimal
shelf placement, and analyze its time complexity.

2. Now consider the case where the height of the books is not constant, but we have the freedom
to adjust the height of each shelf to that of the tallest book on the shelf. Thus the cost of a
particular layout is the sum of the heights of the largest book on each shelf. Give an example
to show that the greedy algorithm of stuffing each shelf as full as possible does not always
give the minimum overall height.
Give an algorithm for this problem, and analyze its time complexity.

Problem 3: Distributed data structure


You have a data structure S that is too large to store on one machine, so you plan to store the n
different elements on k identical machines. The elements are ordered, and, to locate easily, each
machine will store a consecutive sequence of elements. Some elements ei have pointers to other
elements ej . You want to minimize the number of pointers that go between different machines. At
most t elements can fit on any one machine, where tk ≥ n.
a. Formalize the above problem specification as a combinatorial optimization problem, e.g., give
the Instance, Solution Format, Constraints, and Objective.
b. Give an efficient algorithm for the problem.

Problem 4: MAX-SUM among nonadjacent subsequences


Find an efficient algorithm for the following problem:

1
We are given an array P of real numbers V [1..n]. We wish to find a subset of array positions,
S ⊆ [1...n] that maximizes i∈S V [i] subject to no two consecutive array positions being in S. For
example, say V = [10, 14, 12, 6, 13, 4], the best solution is to take elements 1, 3, 5 to get a total of
10 + 12 + 13 = 35. If instead, we try to take the 14 in position 2, we must exclude the 10 and 12 in
positions 1 and 3, leaving us with the second best choice 2, 5 giving a total of 14 + 13 = 27.

Problem 5: Party planning (DPV)


Alice wants to throw a party and is deciding whom to call. She has n people to choose from, and
she has made up a list of which pairs of these people know each other. She wants to pick as many
people as possible, subject to two constraints: at the party, each person should have at least five
other people whom they know and five other people whom they don’t know.
Give an efficient algorithm that takes as input the list of n people and the list of pairs who know
each other and outputs the best choice of party invitees. Give the running time in terms of n.

Problem 6: Magnetic tape


A magnetic tape contains n programs of length l1 , l2 , . . . , ln . We know how often each program
a fraction pi of requests to load a program concern program i, 1 ≤ i ≤ n. This of course
is used: P
implies ni=1 pi = 1. Information is recorded along the tape at constant density, and the speed
of the tape drive is assumed to be a unit constant. Each time a program has been loaded, the
tape is rewound to the beginning. If the programs Pj are held in the order σ1 , σ2 , . . . σn , the average
time required
Pn to load program σ j is Tσj = p σj k=1 lσk . The average time T̄ over all programs
is T̄ = i=1 Ti . Design an efficient algorithm to determine a placement order (σ1 , σ2 , . . . , σn ) to
minimize the average access time T̄ . Prove its correctness and analyze its time complexity.

S-ar putea să vă placă și