{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Graph Search Techniques

# Graph Search Techniques - Graph Search Techniques...

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

Graph Search Techniques I. Introduction II. Tree Traversal Techniques III. Depth-First Search IV. Breadth-First Search V. Biconnectivity: A Major Application of DFS I. Introduction A graph search (or traversal) technique visits every node exactly one in a systematic fashion. Two standard graph search techniques have been widely used: Depth-First Search (DFS) 1. Breadth-First Search (BFS) 2. In the case of rooted binary trees, three recursive traversal techniques are widely used: Inorder Traversal 1. Preorder Traversal 2. Postorder Traversal 3. The tree traversal techniques will be reviewed very briefly. BFS and DFS will ve covered in detail. II. Tree Traversal Techniques Inorder Traversal Procedure inorder( input : T) begin if T = nil then return ; endif inorder(T --> left>; -- traverse the left subtree recursively Graph Search Techniques http://www.seas.gwu.edu/~ayoussef/cs212/graphsearch.html 1 of 10 9/3/2010 4:51 AM

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

View Full Document
visit(T); -- visit/process the root inorder(T --> right>; -- traverse the right subtree recursively end Preorder Traversal Procedure preorder( input : T) begin if T = nil then return ; endif visit(T); -- visit/process the root preorder(T --> left>; -- traverse the left subtree recursively preorder(T --> right>; -- traverse the right subtree recursively end Postorder Traversal Procedure postorder( input : T) begin if T = nil then return ; endif postorder(T --> left>; -- traverse the left subtree recursively postorder(T --> right>; -- traverse the right subtree recursively visit(T); -- visit/process the root end III. Depth-First Search DFS follows the following rules: Select an unvisited node s, visit it, and treat as the current node 1. Find an unvisited neighbor of the current node, visit it, and make it the new current node; 2. If the current node has no unvisited neighbors, backtrack to the its parent, and make that the new current node; Repeat the above two steps until no more nodes can be visited. 3. Graph Search Techniques http://www.seas.gwu.edu/~ayoussef/cs212/graphsearch.html 2 of 10 9/3/2010 4:51 AM
If there are still unvisited nodes, repeat from step 1. 4. Example in class Implementation Observations: the last node visited is the first node from which to proceed. Also, the backtracking proceeds on the basis of "last visited, first to backtrack too". This suggests that a stack is the proper data structure to remember the current node and how to backtrack. Repeat the same example, but this time using a stack Algorithm Procedure DFS(input: graph G) begin Stack S; Integer s,x; while (G has an unvisited node) do s := an unvisited node; visit(v); push(v,S); While (S is not empty) do x := top(S); if (x has an unvisited neighbor y) then visit(y); push(y,S); else pop(S); Graph Search Techniques http://www.seas.gwu.edu/~ayoussef/cs212/graphsearch.html 3 of 10 9/3/2010 4:51 AM

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

View Full Document
endif endwhile endwhile end Time Complexity: Every node is visited once. Also, every edge (x,y) is "crossed" twice: one time when node y is checked from x to see if it i;s visited (if not visited, then y would be visited from x), and another time, when we back track from y to x.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

Graph Search Techniques - Graph Search Techniques...

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

View Full Document
Ask a homework question - tutors are online