
CMPS 101
Winter 2009
Homework Assignment 7
1. (1 Point) p.132: 6.2-5
The code for Max-Heapify is quite efficient in terms of constant factors, except possibly for the
recursive call in line 10, which might cause some compilers to produce inefficient code. Write an
efficient Max-Heapify that uses an iterative control construct (a loop) instead of recursion.
2. (10 Points)
Let and suppose that after INITIALIZE-SINGLE-SOURCE(G, s) is executed, some
sequence of calls to Relax( ) causes to be set to a finite value. Then G contains an s-x path of
weight . (Hint: Use induction on the length of the Relaxation sequence, and recall that this result
was proved in class.)
)(GVx∈
][xd
][xd
3. (1 Point) p.591: 24.1-3
Given a weighted, directed graph ),( EVG
with no negative-weight cycles, let m be the maximum
over all pairs of vertices of the minimum number of edges in a shortest path from u to v.
(Here, the shortest path is by weight, not the number of edges.) Suggest a simple change to the
Bellman-Ford algorithm that allows it to terminate in
Vvu ∈,
1
m passes.
4. (1 Point) p.600: 24.3-1
Run Dijkstra’s algorithm on the directed graph of Figure 24.2, first using vertex s as the source and
then using vertex z as the source. In the style of Figure 24.6, show the d and
values and the
vertices in set S after each iteration of the while loop.
6
3 2 1
4 2 7
5 3
6
z
x
s
1