Professional Documents
Culture Documents
2 a) Do a breadth-first traversal, starting at V3. Shortest path to each other node is the height of that
node in the BFS tree
V3 to V2, V4, V5, V6 =1; V0 = 2; V1 = 3
b) V2 to V0 = 4
V1 = 6
V3 =5
V4 = 7
V5 =5
V6 = 9
d) 2
e) 4
f) For a directed graph, we use the out-neighbourhood: the vertices accessible by an edge from v0. The
out-neighbourhood is {v3, v1}
g) For a directed graph c = e/[k(k-1)], where e is the number of edges in the out-neighbourhood, and k is
the size of the out-neighbourhood. For v0, c = 1/2 = 0.5
4 3
d) What is the difference between a minheap and a maxheap?
Priority 5 Priority 10
Priority 11 Priority 15
a)Draw the state of the heap when a new
element with priority 2 is placed in its proper location.
Priority 3
Priority 5 Priority 10
Priority 5 Priority 3
c) Suppose this heap is used as a priority queue. Suppose another element arrives
with priority 2. Where will it be stored?
In a queue with the current priority 2 node (the root in this case)
An in place algorithm can be performed in the same memory as the initial data
structure (perhaps with a small amount of extra memory necessary). The advantage
is that significantly less than 2*n memory is required to run the algorithm.