Traversals. A systematic method to visit all nodes in a tree Binary tree traversals: Preorder: root, left, right Inorder: left, root, right Postorder: left, right, root General graph traversals (searches) Depthfirst search Breadthfirst search. Inorder(tree t). if t = nil
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
5
2
1
3
8
6
10
7
9
1 2 3 5 6 7 8 9 10
(a BST will always work well with inorder traversal)
5
2
1
3
8
6
10
7
9
5 2 1 3 8 6 7 10 9
5
2
1
3
8
6
10
7
9
1 3 2 7 6 9 10 8 5
+
*
1
3

6
10
1 3 * + 6 10 
5
2
1
3
8
6
10
7
9
DFS: visit all descendents before siblings
5 2 1 3 8 6 7 10 9
This version for binary trees only!
5
2
1
3
8
6
10
7
9
BFS: visit all siblings before their descendents
5 2 8 1 3 6 10 7 9
This version for binary trees only!
This version for binary trees only!
Void Graph::dfs (Vertex v)
{v.visted = true;
for each w adjacent to v
if (!w.visited)
dfs(w);
}
This version for any type of trees (graph)
sourcevertex
differ by one level
5
3
8
4
10
1
5
Not AVL Tree
3
4
1
AVL Tree