Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Tree traversal

A tree is a graph whose degree of node== # of it's children & is acyclic 
Binary tree is a tree with each node having atmost 2 children.
2 ways to traverse each node once:
BFS - level wise
DFS - BY RECURSIVELY TRAVERSING ROOT,LEFT SUBTREE (L) & RIGHT SUBTREE (R)
NOTE: THERE ARE 3! WAYS OF DOING A DFS, BASED ON ORDER OF Root,L,R.     
but only 3 are useful :
Root,L,R- preorder traversal 
L,Root,R- inorder traversal 
L,R,Root- postorder traversal
 
PREVIOUS NEXT
Tagged: #Tree #traversal
ADD COMMENT
Topic
Name
4+6 =