CS330 Introduction to Algorithms December 11, 2012

advertisement
CS330 Introduction to Algorithms
December 11, 2012
Study guide for the nal exam.
This is a study guide for the nal exam, intended to practice the dierent algorithms
we covered in the sections. However, the topic of the exam is everything covered in the
sections AND in the lecture. The solutions to this problem set will NOT be posted, but
you are welcome to ask questions via email.
1. (CLRS 23.1-5) Let e be a maximum-weight edge on some cycle of connected graph
G(V, E). Prove that there is a a minimum spanning tree of graph G0 (V, E − {e})
that is also a minimum spanning tree of G. That is, there is a minimum spanning
tree of G that does not include e.
2. (CLRS 23.1-8) Let T be a minimum spanning tree of a graph G(V, E) and let L
be the sorted list of edge weights of T . Show that for any other minimum spanning
tree T 0 of G, the list L is also the sorted list of edge weights of T 0 .
3. (CLRS 23.2-2) Suppose that we represent the graph G(V, E) as an adjacency
matrix. Give a simple implementation of Prim's algorithm for this case that runs in
O(V 2 ) time.
4. (CLRS 23.2-4) Suppose that all edge weights in a graph are integers in the range
from 1 to |V |. How fast can you make Kruskal's algorithm run? What if the edge
weights are integers in the range from 1 to W for some constant W ?
5. Compute the shortest paths from node s to all other nodes in the graph given by
the edge list below using the Bellman-Ford algorithm. Explain why you cannot use
a similar trick as in the FASTER-ALL-PAIRS-SP algorithm (thus computing only
the values corresponding to iterations 1, 2, 4, . . . , 2m).
S:A:2→C:5
A:B:1→C:4→D:3
B:E:5
C : D : −2
D : B : −1 → E : 6
E:
6. Compute the length of the shortest paths between all pairs of nodes in the graph
dened below. Modify the algorithm that you use, so that you can obtain the
actual paths too, not only their length. Do this exercise both for the FASTER-ALLPATHS-SP algorithm, the Floyd-Warshall algorithm and Johson's algorithm.
A:B:2→E:5
B:C:5
C:A:4→D:6
D:E:1
E:C:5→F :7
F :A:2→B:6
7. Let G(V, E) be a directed graph with node set V = {1, 2, 3, . . . , 9}. Let E contain
edges e(i, j) ∈ E for every 1 ≤ i < j ≤ 9. Dene the edge weights as w(i, j) = 8(j−i).
Compute the length of the shortest paths between all pairs of nodes in G. Use the
algorithm that is fastest for this graph.
8. Let the following edgelist describe the directed graph G:
S:1→2
1:3→4
2:4→5
3:T
4:T
5:T
Assign capacities 1, 1, 1, 2, 2, 2, 3, 3, 3 to the edges in G so that the max-ow from S
to T is (a.) maximal (b.) minimal.
9. Show that if a directed graph with source node s and sink t is such that all edgecapacities are even numbers, then there exists a maximum ow from s to t, so that
the ow on every edge is a positive number. Is it true that if every capacity is odd,
then there exists a max-ow so that the ow on every edge is odd?
10. Write the linear program for the following problem. Then solve it using (a.) graphical
method (b.) the simplex algorithm. Write the dual of the problem.
A gold processor has two sources of gold ore, source A and source B. In order to keep
his plant running, at least three tons of ore must be processed each day. Ore from
source A costs $20 per ton to process, and ore from source B costs $10 per ton to
process. Costs must be kept to less than $80 per day. Moreover, Federal Regulations
require that the amount of ore from source B cannot exceed twice the amount of ore
from source A. If ore from source A yields 2 oz. of gold per ton, and ore from source
B yields 3 oz. of gold per ton, how many tons of ore from both sources must be
processed each day to maximize the amount of gold extracted subject to the above
constraints?
11. Write the linear program for the following problem. Then solve it using (a.) graphical
method (b.) the simplex algorithm. Write the dual of the problem.
A publisher has orders for 600 copies of a certain text from San Francisco and 400
copies from Sacramento. The company has 700 copies in a warehouse in Novato and
800 copies in a warehouse in Lodi. It costs $5 to ship a text from Novato to San
Francisco, but it costs $10 to ship it to Sacramento. It costs $15 to ship a text from
Lodi to San Francisco, but it costs $4 to ship it from Lodi to Sacramento. How
many copies should the company ship from each warehouse to San Francisco and
Sacramento to ll the order at the least cost?
12. Let G(V, E) be a graph. A clique in a graph is a subset of nodes U ⊆ V so that
there is an edge between every two nodes. Thus for every v1 , v2 ∈ U there is an edge
(v1 , v2 ) ∈ E . The CLIQUE problem asks whether G contains a clique of at least
k nodes. An independent set W ⊆ V is a set of nodes, such that there is no edge
between any of the nodes in U . The INDEPENDENT SET problem asks whether
there exists a set of k independent nodes in G. Are CLIQUE and INDEPENDENT
SET in NP? Show a reduction from CLIQUE to the INDEPENDET SET problem,
and vice verse a reduction from INDEPENDENT SET to CLIQUE.
Download