CPS 130 Homework 21 Shortest Paths

due Mon June 24th

Write and justify your answers in the space provided.^{1}

1. Consider a directed weighted graph with non-negative weights and V vertices arranged on a rectangular grid. Each vertex has an edge to its southern, eastern and southeastern neighbours (if existing). The northwest-most vertex is called the root. The figure below shows an example graph with V=12 vertices and the root drawn in black:

Assume that the graph is represented such that each vertex can access all its neighbours in constant time.

(a) How long would it take Dijkstra’s algorithm to find the length of the shortest path from the root to all other vertices?

(b) Describe an algorithm that finds the length of the shortest paths from the root to all other vertices in O(V) time.

(c) Describe an efficient algorithm for solving the all-pair-shortest-paths problem on the graph (it is enough to find the length of each shortest path).

1Collaboration is allowed, even encouraged, provided that the names of the collaborators are listed along with the solutions. Students must write up the solutions on their own.

2 2. Consider a directed weighted graph with non-negative weights which is formed by adding

an edge from every leaf in a binary tree to the root of the tree. Let the graph/tree have n vertices. An example of such a graph with n = 7 could be the following:

We want to design an algorithm for finding the shortest path between two vertices in such a graph.

(a) How long time would it take Dijkstra’s algorithm to solve the problem?

(b) Describe and analyze a more efficient algorithm for the problem.

4