1 / 9

BINARY TREE

TREE TRAVERSALS. BINARY TREE. TREE TRAVERSALS . One of the common operation performed on binary tree is TRAVERSAL. Pass through the tree, enumerating each nodes at once. The contents of each node are printed as we enumerate it. DIFFERENT TRAVERSALS:.

grady
Download Presentation

BINARY TREE

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TREE TRAVERSALS BINARY TREE

  2. TREE TRAVERSALS • One of the common operation performed on binary tree is TRAVERSAL. • Pass through the tree, enumerating each nodes at once. • The contents of each node are printed as we enumerate it.

  3. DIFFERENT TRAVERSALS: • 3 different traversals method are defined PREORDER POSTORDER INORDER These methods are recursively defined. Thus traversing the ROOT, the LEFT SUBTREE & RIGHT SUBTREE

  4. LNR TRAVERSALS PREORDER (Depth-First Order) INORDER Traverse the left subtree. Visit the ROOT. Traverse the right subtree Visit the ROOT. Traverse the left subtree. Traverse the right subtree POSTORDER (Symmetric) Traverse the left subtree. Traverse the right subtree Visit the ROOT. NLR LRN

  5. PREORDER (NLR) N L R 1 N L R N L R 2 3 N L R NLR N L R N L R 6 7 4 5 6 1 2 4 5 3 7 PREORDER:

  6. INORDER (LNR) L N R 1 LNR LNR 2 3 LNR LNR LNR LNR 6 7 4 5 3 4 2 5 1 6 7 INORDER:

  7. POSTORDER (LRN) LRN 1 LRN LRN 2 3 LRN LRN LRN LRN 6 7 4 5 3 4 5 2 6 7 1 PREORDER:

  8. TRAVERSE A B C E F D G H I

  9. ANSWERS • PREORDER: A B D G C E H I F. • INORDER: D G B A H E I C F • POSTORDER: G D B H I E F C A

More Related