Docsity

CS231 Algorithms Problem Set 7 - Graph Algorithms, Assignments of Algorithms and Programming

Toggle sidebar
bg1
1
Wellesley College ◊ CS231 Algorithms ◊ November 15, 1996
Handout #29
PROBLEM SET 7
Due: Monday, November 25
Reading: Handouts 30 & 31; CLR Section 5.4 (Graphs); Chapter 23 (Elementary
Graph Algorithms); Chapter 24 (Minimum Spanning Trees); Sections 25.1 -- 25.2
(Relaxation + Dijkstra’s algorithm). I suggest you skim all the sections and look at the
figures but avoid reading the proofs. Note that some of the graph algorithms I presented
in class are somewhat different than the ones presented in the book.
Suggested Problems: 23.1-1; 23.2-6; 23.3-9; 23.4-2, 23.4-5; 23.5-1, 23..5-3, 23.5-4,
23.5-4; 23-1, 23-2; 24.1-7, 24.2-4, 24.2-5, 25.2-1, 25.2-3, 25.2-5, 25.2-6
Problem 1 [50] Consider the following weighted, directed graph G:
a b c
def g h
ijk
3
4
5
6
7
1
2
4
8
2
7
9
2
6
15
3
10
1
In the following problems, you should assume that G is represented as a collection of
adjacency lists, and that vertices are ordered alphabetically within each adjacency list.
a [5] Draw the tree that is induced by performing breadth-first search starting at node d.
b [15] Use Dijkstra’s algorithm to determine the shortest paths from d to each of the
other vertices. Draw the shortest path tree that is induced by running Dijkstra's algorithm,
and annotate each vertex by its shortest path distance from d.
c [10] Consider the undirected graph G' that is the result of erasing the directions on
each of the edges in G. Draw a minimum spanning tree of G'.
d [10] Draw the tree the is induced by performing a depth-first-search starting at node
d. Label each vertex by its discovery and finishing times (as on CLR p. 479).
e [5] Give a topological sort of the vertices in G.
f [5] Draw a copy of G and circle the strongly-conected components of G.
pf3

Partial preview of the text

Download CS231 Algorithms Problem Set 7 - Graph Algorithms and more Assignments Algorithms and Programming in PDF only on Docsity!

Wellesley College ◊ CS231 Algorithms ◊ November 15, 1996 Handout #

PROBLEM SET 7 Due: Monday, November 25

Reading: Handouts 30 & 31; CLR Section 5.4 (Graphs); Chapter 23 (Elementary Graph Algorithms); Chapter 24 (Minimum Spanning Trees); Sections 25.1 -- 25. (Relaxation + Dijkstra’s algorithm). I suggest you skim all the sections and look at the figures but avoid reading the proofs. Note that some of the graph algorithms I presented in class are somewhat different than the ones presented in the book.

Suggested Problems: 23.1-1; 23.2-6; 23.3-9; 23.4-2, 23.4-5; 23.5-1, 23..5-3, 23.5-4, 23.5-4; 23-1, 23-2; 24.1-7, 24.2-4, 24.2-5, 25.2-1, 25.2-3, 25.2-5, 25.2-

Problem 1 [50] Consider the following weighted, directed graph G:

a b c

d e f g h

i j k

In the following problems, you should assume that G is represented as a collection of adjacency lists, and that vertices are ordered alphabetically within each adjacency list.

a [5] Draw the tree that is induced by performing breadth-first search starting at node d.

b [15] Use Dijkstra’s algorithm to determine the shortest paths from d to each of the other vertices. Draw the shortest path tree that is induced by running Dijkstra's algorithm, and annotate each vertex by its shortest path distance from d.

c [10] Consider the undirected graph G' that is the result of erasing the directions on each of the edges in G. Draw a minimum spanning tree of G'.

d [10] Draw the tree the is induced by performing a depth-first-search starting at node d. Label each vertex by its discovery and finishing times (as on CLR p. 479).

e [5] Give a topological sort of the vertices in G.

f [5] Draw a copy of G and circle the strongly-conected components of G.

Problem 2 [10] (A modified version of CLR 25.2-2, p. 531)

Dijkstra's algorithm assumes that the edge weights of the given graph are non-negative. Here we consider some of the consequences of allowing non-negative edge weights.

a [5] A negative-weight cycle of a weighted graph is a cyclic path whose path weight is negative. Suppose that G is a directed graph with a negative-weight cycle. Explain why the single-source shortest path problem may not be well-defined on such a graph.

b [5] If a graph G has some edges with negative weights but no negative-weight cycles, then the single-source shortest path problem is still well-defined. However, Dijkstra's algorithm is not guaranteed to correctly solve the problem in the presence of negative edge weights. Construct a connected, directed, weighted graph with four vertices such that Dijkstra's algorithm gives an incorrect solution to the single-source shortest path problem.

Problem 3 [15]

a [10] CLR 23.4-3 (p. 488).

b [5] Does your algorithm from part a work for directed graphs? Explain.

Problem 4 [15] CLR 23.4-5 (p. 488)

Extra Credit Problem [20] CLR 24.2-8 (p. 510)