




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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Main points of this past exam are: Algorithms, Programs, Incomplete Instance, Wgraph Data Structure, Adjacency Lists, Missing Fields, Firstedge, Incomplete Representation, Intermediate State, Data Structures
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!
Be neat and concise, but complete.
Exam 1 Solutions Jonathan Turner 9/25/
firstedge a 1
b 2
c 4
d 2
e 1
f 7
edges
a
l 3
lnext 6
rnext e
r 7
wt 1
(^2) d 8 1 3 b
(^3) b 4 6 5 a
(^4) c 5 3 7 b
(^5) a 8 3 6 c
(^6) c 10 1 9 e
(^7) b 9 8 10 f
(^8) d 0 1 0 a
e 0 6 0 b
f 0 2 0 c
9
10
firstedge a 1
b 2
c 4
d 2
e 1
f 7
edges
a
l 3
lnext 6
rnext e
r 7
wt 1
(^2) d 8 1 3 b
(^3) b 4 6 5 a
(^4) c 5 3 7 b
(^5) a 8 3 6 c
(^6) c 10 1 9 e
(^7) b 9 8 10 f
(^8) d 0 1 0 a
e 0 6 0 b
f 0 2 0 c
9
10
Use makeheap to build a 2-heap on the set of items. This takes O(n) time. Then perform k deletemin operations. Since the time per deletemin is O(log n), the running time for k<n/ lg n deletemin operations is O(n).
The figure below shows an assignment of edge weights to a complete graph on 5 vertices that causes Prim’s algorithm to execute changekey once for every edge, assuming that it starts from vertex u 1. The generalization of this graph has n vertices u 1 ,...,un and the weight of the edge from u (^) i to u (^) j is
removed from the heap in step i and changekey will be invoked for all edges (u (^) i ,uj ) with j>i. That is,
u 1 u 2 u 3 u 4 u 5 1 1 1
2 2 2
4
(^33)
1
u 1 u 2 u 3 u 4 u 5 1 1 1
2 2 2
4
(^33)
1
The correctness of any data structure operation depends on its maintaining certain essential properties of the data structure. The data portion of the class declaration for a C++ implementation of a min-max heap data structure is shown below. To make things simpler, you may assume a binary heap (each node has at most two children). What properties of the data must be maintained by programs that operate on it? List as many as you can think of. Hint : a position i is on an even level if lg i is even. Otherwise, i is on an odd level. class minMaxHeap { int N; // max number of items in heap int n; // number of items in heap item *h; // {h[1],...,h[n]} is set of items int *pos; // pos[i] gives position of i in h keytyp *kvec; // kvec[i] is key of item i
... };
for which the round-robin algorithm has a heap of this size at the end of the first pass. Give a tight bound on the time required by the round-robin algorithm on this graph, excluding the time required for initialization.
Construct a star on n vertices with edges of weight 1. A star is a tree in which there is one central
any arbitrary pairs of vertices. Note that the original star is a unique minimum spanning tree for this graph. If we execute the round robin algorithm on this graph, it will combine all vertices into a
dummy nodes from lazy melds.
The running time for the round robin algorithm on this graph (excluding the initialization) is
In all other cases, fcredit is incremented.
Show that fcredit is incremented O (log log log n ) times during each top level find.
The values of g(x) cannot decrease as you go up the tree, so for every value of i, there is at most one node where g(x)=i and g(p(x))>i. So the number of nodes where fcredit gets incremented is at most 2
log log n).
Show that if g ( x )= i at the end of a sequence of operations, then 21 ( ) 2
≤
i debit x.
Every time debit(x) is incremented, the rank(p(x)) increases by at least 1. We only increment debit(x) while g(p(x))=i and g(p(x))=i only so long as ( ()) 2 2 2 1 < −
i+ rank px_. So, once debit(x) is incremented_ 2 1 2
i+ times, g(p(x))>i and debit(x) is never incremented again.
Show that the number of nodes for which the final value of g ( x )= i is at most (^2 )
If g(x)=i, then ( )≥ 22 − 2
i
number of nodes with g(x)=i is at most
n n n k
k L
Show that for each value of i , the sum of the debit variables for all nodes whose final values of g ( x )= i is O ( n ).
The sum is at most n n i i i i 2 2 2 1 2 1
(^112) 2 2 2 2
− + −
=. For i=0 and i=1, this is 2n. For all larger values of i it is
<n, so in all cases, it is O(n).