Docsity

Homework Assignment 7 for CMPS 101 Winter 2009, Assignments of Computer Science

Toggle sidebar
bg1
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
y
t
z
x
s
1
pf2

Partial preview of the text

Download Homework Assignment 7 for CMPS 101 Winter 2009 and more Assignments Computer Science in PDF only on Docsity!

CMPS 101

Winter 2009

Homework Assignment 7

  1. (1 Point) p.132: 6.2- 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.)

x ∈ V ( G ) d [ x ] d [ x ]

  1. (1 Point) p.591: 24.1- Given a weighted, directed graph G = ( V , E ) 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

u , v ∈ V

m + 1 passes.

  1. (1 Point) p.600: 24.3- 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

y

t

z

x

s

1

  1. (10 Points) p.600: 24.3- We are given a directed graph G = ( V , E ) on which each edge ( u , v )∈ E has an associated value r ( u , v ), which is a real number in the range 0 ≤ r ( u , v )≤ 1 that represents the reliability of a communication channel from vertex u to vertex v. We interpret as the probability that the channel from u to v will not fail, and we assume that these probabilities are independent. Give an efficient algorithm to find the most reliable path between two given vertices.

r ( u , v )

  1. (1 Point) p.613: 24.5- Let be a weighted, directed graph with source vertex s and let G be initialized by INITIALIZE-SINGLE-SOURCE( G , s ). Prove that if a sequence of relaxation steps sets

G =( V , E )

π [ s ] to a non-NIL value, then G contains a negative-weight cycle.

2