Set3 - Graph Search Breadth First Search Depth First Search...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 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 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

This note was uploaded on 04/15/2010 for the course INDUSTRIAL ie513 taught by Professor Zeynephuygur during the Spring '10 term at Bilkent University.

Page1 / 27

Set3 - Graph Search Breadth First Search Depth First Search...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online