Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Minimum Spanning Tree - Advanced Data Structures and Algorithms - Solved Exam, Exams of Data Structures and Algorithms

Main points of this past exam are: Advanced Data Structures, Algorithms, Implemented, Wgraph Data Structure, Single Edge, Prim's Algorithm, Dijkstra's Algorithm, Scanning Steps, Diamond”, Fibonacci Heap

Typology: Exams

2012/2013

Uploaded on 03/23/2013

sardai
sardai 🇮🇳

4

(10)

117 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
- 1 -
1. (10 points) Suppose you are given a graph G=(V,E) with edge weights w(e) and a minimum
spanning tree T of G. Now, suppose a new edge {u,v} is added to G. Describe (in words) a
method for determining if T is still a minimum spanning tree for G.
Examine the path in T from u to v. If any vertex on this path has weight larger than that of the new
edge, then T is no longer an MST. We can modify T to obtain a new MST by removing the max
weight edge on this path and replacing it with the new edge.
Explain how your method can be implemented to run in O(n) time if both G and T are
provided as instances of the wgraph data structure.
Using the wgraph for T, we can do a recursive tree traversal in T, starting at vertex u. Once the
traversal reaches v, we “unwind” the recursion, and as we do so, we look for the max weight edge
along the u,v path.
The runtime for a tree traversal is O(n) and the required changes to T can be done in constant time.
Suppose that instead of a single edge, you are given a set of k new edges to add to G. For
small enough k it makes sense to apply your algorithm repeatedly in order to update the
MST, but if k is “too large”, it’s more efficient to re-compute the MST from scratch. How big
does k have to be (as a function of m and n) in order for this to be a better choice? Assume
that the MST is computed using Prim’s algorithm with a d-heap, where d=2.
When d=2, the running time for Prim’s algorithm is O(m log n), so if kn grows faster than this, it
makes sense to recompute from scratch. So, if k>(m/n) log n, it makes sense to recompute the MST.
CS 542 – Advanced Data Structures and Algorithms Jon Turner
Exam 1 Solution
2/14/2013
pf3
pf4
pf5

Partial preview of the text

Download Minimum Spanning Tree - Advanced Data Structures and Algorithms - Solved Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

  1. ( 10 points) Suppose you are given a graph G= ( V , E ) with edge weights w ( e ) and a minimum spanning tree T of G. Now, suppose a new edge { u , v } is added to G. Describe (in words) a method for determining if T is still a minimum spanning tree for G. Examine the path in T from u to v. If any vertex on this path has weight larger than that of the new edge, then T is no longer an MST. We can modify T to obtain a new MST by removing the max weight edge on this path and replacing it with the new edge. Explain how your method can be implemented to run in O ( n ) time if both G and T are provided as instances of the wgraph data structure. Using the wgraph for T, we can do a recursive tree traversal in T, starting at vertex u. Once the traversal reaches v, we “unwind” the recursion, and as we do so, we look for the max weight edge along the u,v path. The runtime for a tree traversal is O(n) and the required changes to T can be done in constant time. Suppose that instead of a single edge, you are given a set of k new edges to add to G. For small enough k it makes sense to apply your algorithm repeatedly in order to update the MST, but if k is “too large”, it’s more efficient to re-compute the MST from scratch. How big does k have to be (as a function of m and n ) in order for this to be a better choice? Assume that the MST is computed using Prim’s algorithm with a d - heap, where d =2. When d=2, the running time for Prim’s algorithm is O(m log n), so if kn grows faster than this, it makes sense to recompute from scratch. So, if k>(m/n) log n, it makes sense to recompute the MST.

CS 542 – Advanced Data Structures and Algorithms Jon Turner

Exam 1 Solution

  1. (10 points) Suppose we apply Dijkstra’s algorithm to the graph shown below, starting from vertex a. List the first 7 vertices that are scanned. a,b,d,e,g,h,j In the diagram label each vertex with its tentative distance after the first 7 vertices are scanned and indicate the parent pointer of each vertex using an arrow pointing from each vertex to its parent. List the next two vertices to be scanned. i,j List the next six. f,g,h,j,i,j What is the total number of scanning steps that Dijkstra’s algorithm will perform on this graph? The number of steps is 3+2(3+2( 5 ))=2 9. If you extended the graph by adding a fourth “diamond” to the left, with edge lengths of 8, 8, 32 and - 24, how many steps would be Dijkstra’s algorithm use for this graph? 3 +2(2 9 )= 61 a b d c 4 4 (^17) - e g f 2 2 8

h j i 1 1 (^3) - 0 4 14 8 10 13 12 17 16 15

  1. ( 15 points) The residual graph shown below is for some flow f on a flow graph G. What is the capacity of the edge connecting e and c in G? Justify your answer. This edge has capacity 7 in the residual graph because the sum of the residual capacities in opposite directions is equal to the original capacity. Is the edge in G directed from c to e or from e to c. Justify your answer. (Hint: consider the total incoming flow at e. ) You may assume that there is no more than one edge joining any two vertices, but you should not assume anything about the direction of the edges at s and t (that is, G may have edges entering s or leaving t ). Consider vertex e. Since this is not the source or the sink, it must satisfy flow conservation. For each or its three incident edges, there are two possible flow values entering e. For the be edge, the inflow is either 0 or 5. For the et edge, the inflow is either 0 or - 3. For the ce edge, the inflow is either 3 or - 4. Since the sum of the inflows must be 0, the inflow on the be edge must be 0, the inflow on the et edge must be - 3 and the inflow on the ce edge must be 3. This implies that the edge is directed from c to e. Find a shortest augmenting path relative to f. Draw the residual graph that results from adding as much flow as possible to this path. The path is sadt and the new residual graph appears below. s a c b d e t

s

a

c

b

d

e

t

  1. (10 points) Let Rf be a residual graph for a min-cost flow f , let p be a source-sink path in Rf with cost c and let q be a source-sink path in Rf with cost d. Let f + be the flow we get when we add enough flow to p to saturate it and let Rf + be the resulting flow graph. Does Rf contain a negative cycle? Explain your answer. No, because f is a min-cost flow and min-cost flows cannot contain negative cycles. If Rf + has no negative cycle, what does that tell us about p? Explain. It implies that p is a min-cost augmenting path, because the absence of a negative cycle implies that Rf+ is a min-cost flow and since we obtained f+ by augmenting along p, it follows that p is a min-cost augmenting path. If d < c does Rf + contain a negative cycle. Explain. Yes. d<c implies that p is not a min-cost augmenting path, so f+ must not be a min-cost flow, and the residual graph for a non min-cost flow must contain a negative cycle. If ( u , v ) is in Rf + but not in Rf , what does that tells us about ( u , v )? Explain. It tells us that (v,u) is on p, since a new edge can only appears in the residual graph when flow is added in the opposite direction. If ( u , v ) is in Rf but not in Rf +, what does that tell us about distf ( u ) and distf ( v ) (where distf ( x ) is the length of the shortest path from the source s to x in Rf )? This means that (u,v) is on p, so distf(v)=distf(u)+cost(u,v)
  1. ( 15 points) In the degree-constrained subgraph problem, we are given a graph G =( V , E ) and a degree bound b ( u ) for every vertex u. The objective is to find a subgraph of G in which every vertex u has at most b ( u ) incident edges. In the graph at right, find a degree-constrained subgraph with 6 edges. Indicate the edges in the subgraph by making them heavier weight. In the weighted version of the problem, each edge e has a weight w ( e ) and we are interested in the degree-constrained subgraph of maximum weight. Describe (in words) an algorithm to solve this problem when the graph is bipartite. Use the graph shown at right to illustrate your solution. (You need not actually produce a max weight subgraph.) Note that the shapes of the vertices define the division of the vertices into subsets. We solve the problem by converting it to a min-cost flow problem, as we did for the max weight matching problem. That is, we add a source vertex with an edge to every vertex in the “left subset” of vertices and a sink with an edge from every vertex in the “right subset”. The edges (s,u) have capacity b(u) and cost 0. The edges (u,t) have capacity b(u) and cost 0. Each original edge {u,v} is turned into a directed edge from the “left vertex” u to v, with cost(u,v)=–wt(u,v) and cap(u,v)=1. We then add flow to the graph using the min-cost augmenting path method. The algorithm halts before finding a maximum flow if the next min-cost augmenting path has non-negative cost. At that point the edges in the “central” part of the graph that have positive flow define a degree-bounded subgraph of maximum weight.

e

c

f

g

d

a

s

t

capacity , cost

b

g a c b d e f 1 3 2 2 2 1 1 e c f 1 2 2 1 2 2 b g d a 1 1 2 6 3 3 3 5 2 4