03_Graph_Search - 15.082 and 6.855J February 11, 2003...

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

View Full Document Right Arrow Icon
1 15.082 and 6.855J February 11, 2003 Lecture 3. Graph Search Breadth First Search Depth First Search Topological Sort
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

03_Graph_Search - 15.082 and 6.855J February 11, 2003...

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