

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


ECS 122A: Algorithm Design and Analysis Handout Z UC Davis — Charles Martel June 3, 2008
1.1. (5 points) ) You are given a computer network where some pairs of computers (but not all) are connected by a 2-way communication line. You know which computers have links directly connecting them, and you want to find out, for a specific computer, its shortest route to each other computer in the network. Distance is defined in terms of how many hops the message must travel (thus if computer A can send a message directly to B, and B can send directly to C and C can send directly to D, the cost from A is 1 to B, 2 to C and 3 to D). There are c computers and L links.
1.2. (5 points) You want to build a railroad line between Sacramento and New York City. There are n possible intermediate cities which could be used, and you know the cost of laying track between any pair of these cities. Your goal is to spend the least total amount to construct all the track needed.
1.3. (8 points) Same as 1.2 except now you want to lay track which will connect all n cities (thus for any pair of cities, you will end up with track connecting them. Note that two routes may share the same track, track laid between say Sacramento and San Francisco can be used for travel in both directions). Again, your goal is to have the total construction cost be as small as possible.
1.4. (8 points) You want to store n files where fi is the number of bytes in the ith file. You have two discs each of which can hold up to D bytes of data. Each file is to be stored on one of the two discs (and you can’t split a file: all of it must be on Disc 1 or on Disc 2).
Your goal is to keep Disc 2 as empty as possible, so you want to assign files so that Disc 1 is as full as possible and the total number of bytes for files assigned to Disc2 is as small as possible.
1.5. (5 points) For video conferencing you sometimes need to find a route in a computer network which has enough capacity for the connection. Suppose you have a network with n nodes and bi,j is the bandwidth of the link connecting nodes i and j (assume bandwidth is symmetric, so bi,j = bj,i). The bandwidth of a connection depends on the smallest link in the route. Thus if you find a route, say i − j − k connecting nodes i and j, the bandwidth of this route is the minimum of bi,j and bk,j.
a) Suppose you are given two nodes i and j and a needed bandwidth B, how would you efficiently find a route from i to j which has bandwidth ≥ B?
b) Now suppose you want a route of maximum bandwidth from i to j. How would you efficiently find such a route?
1.6. (5 points) An Independent Set in a graph is a set S of vertices such that no two vertices in S are connected by an edge. The Independent Set problem is defined as follows: given an undirected graph G = (V,E), and an integer k, can you find an Independent Set of size k in G?
ECS 122A Handout Z: Sample Final 2
Argue that the Independent Set Problem is in N P. NOTE: you are NOT being asked to show it is N P -complete.
1.7. (15 points) For each of the following problems, write true or false. Briefly justify your answer. For the purpose of answering this question you may assume that P is not equal to N P.
(a) Every Problem in N P is hard.
(b) There are instances of the Hamilton Path Problem which can be solved quickly.
(c) A polynomial time algorithm for the decision version of the Traveling Salesman Problem (TSP) would imply a polynomial time algorithm for the optimization version of the TSP problem (where we want the cost of the best tour).
(d) (5 points) A directed graph is strongly connected if and only if a Depth-First-Search started from any vertex will visit every vertex in the graph without needing to be restarted.
2.2. (55 points) For each of the following problems, write true or false. Briefly justify your answer. For the purpose of answering this question you may assume that P is not equal to N P.
(a) Every Problem in P can be solved in under an hour on a fast computer if the input is of size at most 1,000,000.
(b) Huffman codes are better than fixed length codes because they are faster to decode.
(c) Suppose you want to find the cheapest spanning tree which contains two specific edges e 1 and e 2 (note that this may be different from the minimum spanning tree since using these edges may increase the cost). You can find the desired tree by setting the weights of the two edges to 0 and then running Kruskal’s algorithm.
(d) (5 points) For the string ABCABCABA Lempel-Ziv encoding lets you encode the second string ABC (starting at position 4) by the length, pointer pair (3,1). However, we could instead encode the string ABCAB (staring at 4) by the length pointer pair (5,1) and still decode without any problem.
(e) (5 points) Finding the longest simple path in a directed weighted graph is NP-hard. Thus it is hard to find the longest path in every directed graph where each edge has weight -10.
(f ) (5 points) Gzip uses hashing to implement the Lempel-Ziv encoding by finding earlier places in the string where a match might occur. This allo ws Gzip to avoid looking at more than one place earlier in the string to find the best match.
Suppose that we are representing the sets containing the numbers 1 to n using the tree based Union/Find structure where the names of sets are the roots, and other elements have a single pointer to their parent. When doing unions we make the root of the larger tree the new root, and we use path compression when we do a find.