Homework #8

Mostly all-pairs paths, paths in DAGs

# problems
1 Suppose you are given a graph in which each vertex has a cost.  The cost of a path from v to w is the sum of the costs of the interior vertices along the path (the costs of v and w are not included in the sum).
Design an algorithm to solve the all-pairs shortest path problem on this type of graph.
2 CLRS Exercise 25.2-1 on page 699
Run the Floyd-Warshall algorithm on the weighted, directed graph

Show the matrix D(k) that results for each iteration of the outer loop.
3 CLRS Exercise 24.3-2 on page 663
Give a simple example of a directed graph with negative-weight edges for which Dijkstra's algorithm produces incorrect answers.

# hard problems
4 Given a weighted directed graph G=(V,E,p), where p(e), the weight of edge e, is the probability that an attempt to traverse that edge is successful. Any unsuccessful attempt causes instant death.

Describe an efficient algorithm to find a path from the start vertex s to the goal vertex t that maximizes the probability of a successful journey.

5 CLRS Exercise 24.2-4 on page 658
Give an efficient algorithm to count the total number of paths in a directed acyclic graph. Analyze your algorithm.
6 Consider a DAG with n vertices, labeled by the integers 1 through n.  Call this graph G.  There is an edge from vertex x to vertex y if and only if x > 2y.
  1. How many edges does graph G have as a function of n?
  2. Explain how the transitive closure of G would be different from G, or why it would not be different.
7 We are given a directed graph G on n vertices.  Give an algorithm to fill in the entries of an n × n matrix M such that
M[i, j] =   the length of the longest path from vertex i to vertex j,
M[i, j] =   – 1     if there is no path from i to j and
M[i, j] =   n + 1 if there are paths of unbounded length from i to j.
Analyze the time and space complexity of your algorithm.

Hint:  This problem can be solved by dynamic programming.  Let C[i, j, k] be the length of the longest path from i to j, using no intermediate vertex numbered higher than k.  Obtain a recurrence and boundary conditions for C[i, j, k].  Allow for the possibility that the graph may have some self loops, i.e., edges from a vertex to itself.


Last modified: Mar 27, 2020