cse101_11_2_11 - 2. Breadth-first search a. Procedure BFS...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Breadth-First search 1. Distance in graphs a. DFS finds all nodes reachable from a given node as well as explicit paths to those nodes (in search tree) These are not the shortest possible paths. b. The distance between two nodes is the length of the shortest path connecting them. c. Physical model Tennis ball for each node, string as edge To find shortest paths from A, hold up ball A. d. To find distances from a starting ndoe s: d.i. Find node at distance 0 (just s) d.ii. Then distance 1 d.iii. Then distance 2 … Once we have all nodes at distance <= d we can find the nodes at distance d + 1: They are: Adjacent to nodes at distance d Have not been identified yet.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2. Breadth-first search a. Procedure BFS (G,s) Input: Graph G = (V, E) ; node s in V Output: For all nodes u reachable from s, dist[u] is set to the distance from s Distance for non-reachable nodes = infinite b. For all u in V: Dist[u] = infinite Dist[s] = 0; Q = (empty queue) Inject (Q,s) While Q is not empty: U = eject (Q) For (all (u,w) in E: If dist[w] = infinite: Dist[w] = dist[u] + 1 Inject(Q,w) Queue A B C D E F [A] 0 I I I I I (I = infinite) [B D] 0 1 I 1 I I [D C E] 0 1 2 1 2 I [C E] 0 1 2 1 2 I [E F] 0 1 2 1 2 3 c. Why does it work? Proof by induction Look at the book for details d....
View Full Document

Ask a homework question - tutors are online