This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Graph Search Breadth First Search Depth First Search Topological Sort 2 Overview ◆ 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. 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 end ; ◆ end 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 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 nondecreasing 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 1 2 4 5 3 6 9 7 8 3 1 1 2 2 5 3 4 6 8 6 7 9 6 9 5 9 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;...
View
Full Document
 Spring '10
 zeynephuygur
 Graph Theory, Depthfirst search, Cutset Theorem

Click to edit the document details