



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
Main points of this exam paper are: General Greedy Method, Minimum Spanning Trees, General Greedy Method, Kruskal's Algorithm, Data Structure Operation, Essential Properties, Data Structure, Class Declaration, D-Heap Data Structure, Prim's Algorithm
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Be neat and concise, but complete.
Kruskal’s algorithm is a special case of the general greedy method.
certain essential properties of the data structure. The data portion of the class declaration for the C++ implementation of the d -heap data structure is shown below. What properties of the data must be maintained by programs that operate on it? class dheap { int N; // max number of items in heap int n; // number of items in heap int d; // base of 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
... };
and a minimum spanning tree for that graph, represented using a vector of parent pointers. Now suppose that the weight of one of the non-tree edges is changed. Describe an O ( n ) time algorithm to modify the spanning tree, to reflect the change in the edge weight. You may describe your algorithm in words, but be complete and precise. Be sure to explain what changes are made to the vector of parent pointers. You may want to draw a picture and explain your algorithm using the picture.
after performing a deletemin operation.
c 7,0 (^) q 8,
a 4,3 (^) p 6,
n 7,0 (^) e 5,0 g 9,0 h 8,
f 5,
key , rank
r 7,0 i 5,2 (^) o 6,
m 7,1 (^) k 5,
!!!!
!!!!
!!!!
!!!!
s 6,
!!!! denotes a set mark bit
d 2,3 l^ 4,2^ b 3,
cc 7,07,0 (^) qq 8,08,
aa 4,34,3 (^) pp 6,06,
nn 7,07,0 (^) ee 5,05,0 gg 9,09,0 hh 8,28,
ff 5,15,
key , rank
rr 7,07,0 ii 5,25,2 (^) oo 6,06,
mm 7,17,1 (^) kk 5,05,
!!!!
!!!!
!!!!
!!!!
ss 6,06,
!!!! denotes a set mark bit
dd 2,32,3 ll^ 4,24,2^ bb 3,13,
smallest weight edge on the path. The objective of the largest bottleneck path problem is to find paths for which the bottleneck capacity is largest. Define a largest bottleneck path tree to be a spanning tree, rooted at a source vertex s , in which all paths are largest bottleneck paths. Show how to modify the theorem shown below, so that it applies to largest bottleneck path trees.
Theorem. Let T be a spanning tree with root s of a directed graph G. Define distance ( v ) to be the length of the path from s to v in T. T is a shortest path tree if and only if, distance ( w ) ≤ distance ( v ) + length ( v , w ), for every edge [ v , w ] in G.
A C++ implementation of Dijkstra’s algorithm appears below. Show how to modify it so that all the paths in the tree that is returned are largest bottleneck paths.
void spt_dijkstra(wdigraph& G, vertex u, vertex p[], int d[]) { // Find a shortest path tree of G using Dijkstra's algorithm // and return it in p as an array of parent pointers, with // d giving the shortest path distances. vertex v,w; edge e; dheap S(G.n,max(3,G.m/G.n));
for (v = 1; v <= G.n; v++) { p[v] = Null; d[v] = BIGINT; } p[u] = u; d[u] = 0; S.insert(u,0); while (!S.empty()) { v = S.deletemin(); for (e = G.firstout(v); e != Null; e = G.nextout(e)) { if (G.w(e) < 0) fatal("spt_dijkstra: negative length edge"); w = G.head(e); if (S.member(w) && d[v] + G.w(e) < d[w]) { d[w] = d[v] + G.w(e); p[w] = v; S.changekey(w,d[w]); } else if (!S.member(w) && p[w] == Null) { p[w] = v; d[w] = d[v] + G.w(e); S.insert(w,d[w]); } } } p[u] = Null; return; }