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

Prim Algorithm - Advanced Data Structures and Algorithms - Solved Exam, Exams of Data Structures and Algorithms

Main points of this past exam are: Prim's Algorithm, Algorithms, Advanced Data Structures, General Greedy, Minimum Spanning Tree, Implicitly Colors, Edge Weights, Consistent, Changkey, Million.

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) Prim’s algorithm can be viewed as applying the blue rule of the general greedy
method n–1 times to create a minimum spanning tree. It then implicitly colors the remaining
edges red without ever considering their edge weights. Explain why this last step is
consistent with the general greedy method.
Any edge e that remains uncolored at the end of Prim’s algorithm joins two vertices in the tree. The
tree path joining those two vertices has all of its edges colored blue, so e together with the tree path
forms a cycle that the red rule can be applied to, and since the only uncolored edge on that cycle is e,
we can color it red without considering the edge weights.
Suppose an application uses Prim’s algorithm for minimum spanning trees and we happen
to know that for the graphs that arise in the application, changkey is called at most n4/3 times.
Based on this, derive an estimate for the best choice of d for this application. How many
levels will the heap have if n=106?
Increasing d makes insert and changekey run faster, while it makes deletemin slower. We can get the
right approximate value by making the time for all the inserts and changekeys equal to the time for
the deletemins. Setting (n+n4/3) logdn = nd logdn gives us d=1+n1/3. With this choice of d, the heap
will have four levels.
CS 542 – Advanced Data Structures and Algorithms
Exam 1 Solutions
J
onathan Turne
r
2/18/2010
pf3
pf4
pf5

Partial preview of the text

Download Prim Algorithm - Advanced Data Structures and Algorithms - Solved Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

  1. (10 points) Prim’s algorithm can be viewed as applying the blue rule of the general greedy method n –1 times to create a minimum spanning tree. It then implicitly colors the remaining edges red without ever considering their edge weights. Explain why this last step is consistent with the general greedy method. Any edge e that remains uncolored at the end of Prim’s algorithm joins two vertices in the tree. The tree path joining those two vertices has all of its edges colored blue, so e together with the tree path forms a cycle that the red rule can be applied to, and since the only uncolored edge on that cycle is e, we can color it red without considering the edge weights. Suppose an application uses Prim’s algorithm for minimum spanning trees and we happen to know that for the graphs that arise in the application, changkey is called at most n 4/3^ times. Based on this, derive an estimate for the best choice of d for this application. How many levels will the heap have if n =10 6?

Increasing d makes insert and changekey run faster, while it makes deletemin slower. We can get the right approximate value by making the time for all the inserts and changekeys equal to the time for the deletemins. Setting (n+n 4/3^ ) logd n = nd log (^) d n gives us d=1+n 1/3. With this choice of d, the heap will have four levels.

CS 542 – Advanced Data Structures and Algorithms

Exam 1 Solutions

Jonathan Turner 2/18/

  1. (12 points) Consider a 2-heap on 16 thousand items with key values that are randomly distributed between 0 and 1 million. If we inserted an item with a key of 0 into the heap, approximately how many iterations would siftup perform? Explain. In this case, almost all of the items in the heap have a larger key than the new item, so we would expect siftup to go all the way from the bottom of the heap to the top, which is 14 levels in this case.

What if the inserted item had a key of 500 thousand? Explain. Since half of the heap items are in the bottom level, we would expect those items above the bottom level to have key values smaller than 500 thousand. So typically, siftup would only go one or two iterations in this case.

Suppose that instead of insert, we did a deletemin. Approximately how many iterations would the siftdown procedure perform? Explain.

The siftdown operates on the item that was originally in the last position of the heap. So, it will typically have a larger key than the items in all but the last level. So, we would expect the siftdown to go through all 14 levels or nearly that many.

Suppose that we selected an item at random and did a changekey on that item with a new key value of 60,000. Estimate the number of levels the item will move. Explain.

Since most of the items are on the bottom few levels, it’s likely that the randomly selected item will also come from the bottom few levels. It’s new key value is about 1/16 from the top, which means its final position would most likely be in the fourth or fifth level up from the bottom. So, we can expect it to siftup by three or four levels.

  1. (9 points) The diagram shown below is the residual graph for some flow. Identify a shortest augmenting path in this residual graph. How much flow can be added to this path?

sadt is a shortest augmenting path on which we can add 2 units of flow Identify a maximum capacity augmenting path in the residual graph. How much flow can be added to this path? scebdt is a max capacity path on which we can add 4 units of flow.

Find the path that would be selected by the capacity scaling algorithm if the current scale factor was 3. How much flow can be added to this path?

The capacity scaling algorithm would return the path scadt on which we can add 3 units of flow.

s

a

c

b

d

e

t

7

4

3

2

3

2

2

(^4 2 )

4

3

2

3

1

2

2

  1. (10 points) Let G be a directed graph in which each edge ( u , v )has a length length ( u , v ). Describe (in words) an algorithm to determine if G has k edge disjoint paths between a given pair of vertices x and y , where the total length of the paths is no larger than some bound B. Explain how this computation can be done in O( mn + km log n /log (2+ m / n )) time. We can solve the problem by converting it to a minimum cost flow problem. Assign a capacity of 1 to all of the edges in the graph and use the given lengths as the edge costs. Add a source vertex s with a single edge of capacity k to x, and a sink vertex t with a single edge of capacity k from y. A max flow for this graph has value k and we can find a min-cost max flow by applying the least-cost augmenting path algorithm for k steps. The edges from the original graph with positive flow define a set of k edge- disjoint paths from x to y. Return true if the sum of their edge lengths is no more than B. We need O(mn) time to transform the edge costs at the start of the algorithm and then O(m log n /log (2+ m / n )) time for each of the k augmenting path steps, assuming we implement Dijkstra’s algorithm, using a d-heap.
  1. (15 points) Consider an execution of the shortest augmenting path algorithm. Suppose that from step number 100 to step number 200, all the augmenting paths have 50 edges. Let k= 160 and suppose that x is on the augmenting path chosen during step k +1. Give an upper bound on the value of level (^) k ( x ) (recall that level (^) k ( x ) is the number of edges in a shortest path from the source vertex to x in the residual graph immediately following step k ). Explain your answer.

level (^) k ( u )≤ 50 since vertices on the augmenting path must have level values no larger than level(t)=50.

Suppose that during step k+1 , an edge ( u , v ) is added to the residual graph. Give an equation relating the value of level (^) k ( u ) to level (^) k ( v ). Explain your answer

level (^) k ( u )= level (^) k ( v )+1, because an edge is added to the residual graph only when the reverse of that edge is on the augmenting path, and edges on the augmenting path have increasing level values.

Give an equation relating the value of level 99 ( u ) to level 99 ( v ). Explain your answer.

level 99 ( u )= level 99 ( v )+1, because if the level values of either u or v had increased in steps 100 thru 160 then the edge (v,u) could not have been chosen for the augmenting path in step 161.

Let S be the set of edges ( x , y ) for which level 99 ( y )= level 99 ( x )+1. Is it possible for S to have exactly 85 edges? Why or why not?

This is not possible. Every augmenting path step from 100 to 200 must saturate an edge in S and each edge can be saturated at most once while the path lengths remain at 50. So, there must be at least 100 edges in S.