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

Data Structure - Advanced Data Structures and Algorithms - Exam, Exams of Data Structures and Algorithms

Main points of this exam paper are: Advanced Data Structures, Prim's Algorithm, Worst-Case Analysis, Changekey Procedure, Weighted Graph, Edge Weights, Round-Robin Algorithm, Partition Data Structure, Minimum Spanning Tree Algorithm, Findmax Operation

Typology: Exams

2012/2013

Uploaded on 03/23/2013

saruy
saruy 🇮🇳

4.5

(114)

132 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
- 1 -
Be neat and concise, but complete.
1. (5 points) An incomplete instance of the wgraph data structure is shown below. Fill in all
the missing entries.
CS 542 – Advanced Data Structures and Algorithms
Exam 1
J
onathan Turne
r
9/29/05
5
f
irstedge a
3
b
c
9
d
e
10
f
edges
a
l3
lnext 9
rnext e
r
7
wt
1
d0 71
2
4 8 a6
3
c7 03
4
1 2 d3
5
c0 01
6
c6 0 f8
7
0 4 c1
8
e10 56
2 6 e2
9
10
5
f
irstedge a
3
b
c
9
d
e
10
f
edges
a
l3
lnext 9
rnext e
r
7
wt
1
d0 71
2
4 8 a6
3
c7 03
4
1 2 d3
5
c0 01
6
c6 0 f8
7
0 4 c1
8
e10 56
2 6 e2
9
10
pf3
pf4
pf5
pf8

Partial preview of the text

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

Be neat and concise, but complete.

  1. (5 points) An incomplete instance of the wgraph data structure is shown below. Fill in all the missing entries.

CS 542 – Advanced Data Structures and Algorithms

Exam 1

Jonathan Turner 9/29/

firstedge a 5

b 3

c

d 9

e

f 10

edges

a

l

3

lnext

9

rnext

e

r

7

wt 1

(^2) d 0 1 7

(^34 68) a

(^4) c 7 3 0

(^51 32) d

(^6) c 0 1 0

(^7) c 6 8 0 f

(^80 14) c

e 10 6 5

2 2 6 e

9

10

firstedge a 5

b 3

c

d 9

e

f 10

edges

a

l

3

lnext

9

rnext

e

r

7

wt 1

(^2) d 0 1 7

(^34 68) a

(^4) c 7 3 0

(^51 32) d

(^6) c 0 1 0

(^7) c 6 8 0 f

(^80 14) c

e 10 6 5

2 2 6 e

9

10

  1. (10 points) In the worst-case analysis of Prim’s algorithm, we saw that the number of calls to the changekey procedure was O ( m ). Show that it is also Ω( m ). More specifically, show that it is Ω( n^2 ). Do this by showing that for each value of n , there is a weighted graph with Ω( n^2 ) edges and that changekey is invoked when most of these edges are examined. Be sure to specify the edge weights. Draw a picture of the graph for the case of n =5.
  1. (15 points) The minimum spanning tree algorithm shown below is similar to Prim’s algorithm, but in this case the heap stores all the edges with exactly one endpoint in the set of tree vertices.

procedure minspantree( graph G , set tree_edges ); vertex u , v ; set tree_vertices ; heap S ; tree_vertices := {1}; tree_edges := {}; for {1, v } ∈ edges(1) ⇒ insert({1, v }, cost (1, v ), S ); rof ; do S ≠ {} ⇒ { u , v } := deletemin( S ); // assume utree_vertices tree_vertices := tree_vertices ∪ { v }; tree_edges := tree_edges ∪ { u,v }; for { v,w } ∈ edges ( v ) ⇒ if wtree_vertices ⇒ delete({ v,w }, S ); | wtree_vertices ⇒ insert({ v,w }, cost ( v,w ), S ); fi; rof ; od ; end ;

Explain why this algorithm is an instance of the general greedy method.

Give an expression for the time required by all the deletemin operations, in terms of the number of vertices ( n ), the number of edges ( m ) and the heap parameter ( d ). Similarly, give an expression for the time required by all the insert operations and all the delete operations.

What choice of d gives the best overall running time? Why?

.

  1. (10 points) Problem set 1 discusses a min-max heap, a data structure that supports both a findmin operation and a findmax operation. In the implementation discussed in the problem set, nodes at even distances from the root have the smallest key value in their subtree, while nodes at odd distances from the root have the largest key value in their subtree.

An alternative way implement a min-max heap is to store the items in two separate d -heaps, one of which is organized to support the findmin operation and the other organized to implement the findmax operation. How does the space used in these two implementations compare? Assume that the min-max heap is not required to provide a general delete operation or a changkey operatiion, but is required to implement both deletemin and deletemax.

Give an asymptotic upper bound on the running time of the changekey operation on this alternate implementation of the min-max heap, in the case when the key increases in value. Also, give an upper bound on its running time when the key decreases in value. How is the running time affected by the value of d used in the underlying d -heaps? What is the best choice for d. Justify your answers.

Give an asymptotic upper bound on the running time of the insert operation. How is the running time affected by the value of d used in the underlying d -heaps? What is the best choice for d from the perspective of the insert operation? Justify your answers.

  1. (15 points) Consider a version of the partition data structure that uses path compression, but does not use link-by-rank. In such a version, we can reduce the space consumed by the algorithm, by eliminating the rank variables. The link subroutine in this version would simply make the parent pointer of the first argument equal to the second argument. To analyze the performance of this version, it’s useful to define a function r which takes the role of the rank in the analysis. For each node x , r ( x ) is initialized to zero. Then, during the link operation that makes node x the child of node y , r ( y ) is assigned the value max{ r ( y ),1+ r ( x )}.

Define level x ( ) = ⎢⎣lg(1 + r p x ( ( )) − r x ( ))⎥⎦. What is the largest value that level ( x ) can have?

Assuming that the credit and debit variables used in the original analysis are defined and assigned values in the same way as in the original analysis, give a tight upper bound on the value for fcredit after m operations have been done. Justify your answer.

Suppose that debit (x) is incremented during a find operation and that level (x)= i before the find. If p ( x ) =w before the find and p ( x )= z after the find , how does the value of r ( z ) compare to r ( w )? Explain.

How many times can debit ( x ) be incremented while level ( x )= i? Why?

Give an upper bound on the final value of debit ( x ). Explain.