views:

25

answers:

1

Hello, I am not understanding how to draw a Binary Tree give traversals. Could someone explain to me inorder, preorder, and postorder traversals in a more efficient way?

For example:

Reconstruct the exact BINARY tree given the following traversals:

Inorder: 9, 2, 10, 6, 5, 8, 3, 1, 4, 7 Post order: 9, 10, 2, 6, 8, 3, 7, 4, 1, 5

Any help is much appreciated!

A: 

One of the best example I've found explaining this is here (click 'Traversals' on the left menu, then 'Start Lesson' for the demo) as it has a completely pictorial explanation of what is happening

Short version

  • Preorder is DLR: Data, Left, Right
  • Inorder is LDR: Left, Data, Right
  • Postorder is LRD: Left, Right, Data
Dave