



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this exam paper are: Post-Visit Labels, Statements, Simple Counterexample, Infinity, Depth-First Search, Post-Visit Labels, Songly-Connected, Strongly-Connected Component, Divide-And-Conquer, Scenarios Outlines
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!




CS-170 Efficient Algorithms & Intractable Problems, Spring 2006, Professor Sinclair
6:00-8:00pm, 2 March
Notes: There are four questions on this midterm. Answer each question part in the space below it, using the back of the sheet to continue your answer if necessary. If you need more space, use the blank sheet at the end. None of the questions requires a very long answer, so avoid writing too much! Unclear or long-winded solutions will be penalized. The questions vary quite a bit in difficulty, so if you are having problems with part of a question, leave it and try the next one. The approximate credit for each question part is shown in the margin (total 65 points). Points are not necessarily an indication of difficulty!
Your Name: Your Section No:
1. True or False?
For each of the following statements, say whether each statement is True or False. If it is True, give a brief explanation (~ one sentence); if it is False, give a simple counterexample.
(i) For any two non-negative functions f ( n ) and g ( n ), both of which tend to infinity, we must have either f ( n ) = O ( g ( n )) or g ( n ) = O ( f ( n )).
(ii) Suppose the pre- and post-visit labels of two vertices in a depth-first search on an undirected graph G = ( V , E ) satisfy pre( u ) < post( u ) < pre( v ) < post( v ). Then there can be no edge between u and v.
(iii)Suppose the pre- and post-visit labels of two vertices in a depth-first search on a directed graph G = ( V , E ) satisfy pre( u ) < post( u ) < pre( v ) < post( v ). Then there can be no edge (in either direction) between u and v.
3pts
3pts
3pts
[Q1 continued]
(iv) In a DFS of a directed graph G , the set of vertices reachable from the vertex with lowest post- visit label is a strongly-connected component of G.
(v) In a DFS of a directed graph G , the set of vertices reachable from the vertex with highest post-visit label is a strongly-connected component of G.
(vi) If an optimal Huffman code has codewords of length 1 and 3, then it must also have at least one codeword of length 2.
3pts
3pts
3pts
3. Dijkstra’s algorithm
(a) Run Dijkstra’s algorithm on the following directed graph, to compute distances from node A to all the other nodes. Fill in the entries of the table, showing the “dist” label of each node after each iteration.
Iteration Node 0 1 2 3 4 5
(b) Consider the following problem. You are given a directed graph representing a network of highways, together with a black box that gives you the predicted travel time for each edge in the graph. Because traffic conditions vary, this travel time depends on the time of day at which you start to traverse the edge. Specifically, the travel time on edge e = ( u , v ) is a positive function ℓ e ( t ), such that if you leave node u at time t then you will arrive at v at time t + ℓ e ( t ). The black box allows you to query the predicted travel time ℓ e ( t ) for any edge e and any time t in advance. Travel times satisfy the physicality constraint: t + ℓ e ( t ) < t' + ℓ e ( t' ) if t < t' , i.e., you cannot arrive at v earlier by leaving u later. Your goal is to figure out a route, starting at time t 0 from node s , to a destination node z , so that your predicted arrival time at z is as early as possible. Explain carefully how to modify Dijkstra’s algorithm so that it solves this problem. (You do not need to give the full pseudocode; just indicate how the algorithm changes.)
(c) Explain briefly why your algorithm breaks down if the physicality constraint is removed.
6pts
6pts
2pts
4. Yet another MST algorithm
We have seen several algorithms for computing a Minimum Spanning Tree (MST) in a connected, undirected graph. This question discusses yet another algorithm for this problem. For simplicity, we assume that all the edge weights are distinct.
(a) For each vertex v , let ev be the edge with minimum weight incident on v. Prove that there is a MST of G that contains ev.
(b) The new algorithm is based on the observation in part (a). It uses the operation of “contracting” an edge: when an edge e = { u , v } is contracted, its endpoints u , v are merged into a single vertex. If either (or both) of u , v have an edge to another vertex w , then the merged vertex also has an edge to w ; the weight of this new edge is the minimum of the weights of the edges { u , w } and { v , w }. Here is the algorithm:
function MST( G = ( V , E )) X =Ø while | V | > 1: for each v in V : ev = minimum edge weight incident on v for each edge ev : add ev to X contract ev return X
Using part (a), explain carefully why this algorithm outputs a MST of G.
5pts
4pts