You are on page 1of 2

Section 2.5.

Shortest Path Problems

69

2.4.2 Find a maximal spanning tree for each of graphs of Figure 2.23 using either Kruskal's algorithm or Prim's algorithm. 2.4.3 The following is a third algorithm for finding a minimal spanning tree of a connected weighted graph G with n vertices where each weight is non-negative. Simply delete one by one those edges of G with largest weight, provided each such deletion does not result in a disconnected graph, until there are just n 1 edges left. Then the resulting subgraph is a minimal spanning tree of G. Perform this algorithm on the graphs of Figure 2.23. 2.4.4 Prove that if G is a connected weighted graph in which no two edges have the same weight then G has a unique minimum spanning tree.

2.5 Shortest Path Problems (1) The Breadth First Search (BFS) technique. Let G be a graph and let s,t be two specified vertices of G. We will now describe a method of finding a path from s to t , if there is any, which uses the least number of edges. Such a path, if it exists, is called a shortest path from s to t. The method assigns labels 0,1,2,... to vertices of G and is called the Breadth First Search (BFS for short) technique. It is given by the following algorithm. The Breadth First Search Algorithm Step 1. Label vertex s with 0. Set i = 0. Step 2. Find all unlabelled vertices in G which are adjacent to vertices labelled i. If there are no such vertices then t is not connected to s (by a path). If there are such vertices, label them i + 1. Step 3. If t is labelled, go to Step 4. If not, increase i to i + 1 and go to Step 2. Step 4. The length of a shortest path from s to / is i + 1. Stop. For example, for the graph of Figure 2.24, first s is labelled 0. Then a and / are labelled 1. Then 6, d and e are labelled 2. Then c and J are labelled 3. Since tis labelled 3, the length of a shortest path from s to t is 3. For the graph of Figure 2.25, first a is labelled 0. Then a, 6 and c are labelled 1. Then d is labelled 2. But now there are no unlabelled vertices adjacent to d , tiic only vertex labelled 2. Hence, by Step 2, we can conclude that there is no path from a to (. We now show that Step 4's statement is justified by proving that the Breadth First Search works. Theorem 2.16 A vertex v of the graph G is labelled the number X ( v ) b y the BFS algorithm above if and only if the length of a shortest path from s to v is A(i>). (In particular i f t is labelled n then the shortest path from s to t has n edges.)

You might also like