cybill
Uploaded by
14 SLIDES
308 VUES
150LIKES

Understanding Tree Traversal: Preorder, Inorder, and Postorder Notations

DESCRIPTION

This guide covers the fundamentals of tree traversal techniques, specifically focusing on Preorder, Inorder, and Postorder notations. Explore how each traversal method processes nodes—Preorder visits the root first, Inorder processes the left subtree, the root, and then the right subtree, while Postorder visits the left and right subtrees before the root. The guide also distinguishes between infix, prefix, and postfix notations, highlighting the importance of parentheses in infix expressions. Examples are provided to demonstrate the evaluation of expressions in different notations.

1 / 14

Télécharger la présentation

Understanding Tree Traversal: Preorder, Inorder, and Postorder Notations

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. 10.3 Tree Transversal

  2. Pre/post fix notation and order • See handout . a . b c . d e f g h i j k

  3. Preorder transversal- root first, then left to right a . b c . d e f g h i j k

  4. Inorder transversal- left tree, then root, then rest of trees- left to right a b c d e f g h i j k

  5. Postorder transversal- left to right, then root last a . b c . d e f g h i j k

  6. Infix, prefix, and postfix • See handout • Infix order is ambiguous – so parentheses are required • Prefix and postfix are not– so parentheses are unnecessary • Prefix- “Polish notation” • Read from R to L • Operations are on the L • Postfix • Read from L to R • Operations are on the R

  7. Example– transverse in 3 ways, and evaluate each notation +  * 3 2 5 2 • Preorder- prefix • Inorder-infix • Postorder-postfix

  8. Example- prefix • Evaluate a prefix expression + - * 2 3 5 /  2 3 4

  9. Ex- postfix 7 2 3 * - 4  9 3 / +

  10. Example– transverse in 3 ways, and evaluate each notation +  * 5 2 3 4 • Preorder- prefix • Inorder-infix • Postorder-postfix -  *

  11. Find the value of each prefix expression (R to L,operations on the L) • - * 2 / 8 4 3 •  - * 3 3 * 4 2 5

  12. Find the value of each prefix expression (R to L,operations on the L) • + -  3 2  2 3 / 6 – 4 2 • * + 3 + 3  3 + 3 3 3

  13. Find the value of each postfix expression (L to R, operations on R) • 5 2 1 - - 3 1 4 + + *

  14. Find the value of each postfix expression (L to R, operations on R) • 9 3 / 5 + 7 2 - * • 3 2 * 2  5 3 – 8 4 / * -

More Related