03_Graph_Search

# 03_Graph_Search - 15.082 and 6.855J Lecture 3 Graph Search...

This preview shows pages 1–8. Sign up to view the full content.

1 15.082 and 6.855J February 11, 2003 Lecture 3. Graph Search Breadth First Search Depth First Search Topological Sort

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Overview Today: Different ways of searching a graph a generic approach breadth first search depth first search data structures to support network search Fundamental for most algorithms considered in this subject
3 Searching a Directed Graph ALGORITHM SEARCH INPUT: A directed network G, and node s OUTPUT: The set of nodes {j : there is a directed path from s to j in G}. These are the nodes reachable from s. A node is either marked or unmarked . Initially only node s is marked. If a node is marked, it is reachable from node s An arc (i,j) A is admissible if node i is marked and j is not. pred(i) is the predecessor of i on the path from s to i.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Algorithm Search Begin Initialize. while LIST ø do begin select a node i in LIST; if node i is incident to an admissible arc (i,j) then begin mark node j; pred(j) := i; next := next + 1 order(j) := next; add node j to LIST; end else delete node i from LIST
5 Initialize Initialize begin unmark all nodes in N; mark node s; pred(s) = 0; {that is, it has no predecessor} next := 1; (next is a counter} order(s) := next; LIST = {s} end Breadth First Search Animation

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Breadth First Search Final output from breadth first search It provides a label of the nodes that is called a breadth first search labeling. We say that a labeling of the nodes is a breadth first search labeling if the nodes are labeled in non-decreasing order of “distance” from the origin, where distance is the min number of arcs on the path from the origin. Next: how to implement this so that it runs in O(n+m) time. 9 8 7 6 4 3 1 1 2 2 5 3 4 8 7 6
7 Begin Initialize. while LIST ø do begin select a node i in LIST; if node i is incident to an admissible arc (i,j) then begin mark node j; pred(j) := i; next := next + 1 order(j) := next; add node j to LIST; end else

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/05/2010 for the course EE 15.082 taught by Professor Orlin during the Spring '10 term at Visayas State University.

### Page1 / 26

03_Graph_Search - 15.082 and 6.855J Lecture 3 Graph Search...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online