Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Traversing tree

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: #Traversing #tree
ADD COMMENT
Topic
Name
8+1 =