Question

I have Binary Search tree and have to perform three types of tree traversal: Are this results correct?

Pre-order (root,left,right): 30,15,59,43,40,92

In-order (left,root,right): 15,30,59,40,43,92

Post-order (left,right,root): 15,59,40,43,92,30

enter image description here


UPDATE:

In-order: 15,30,40,43,59,92 (projection?)

Post-order: 15,40,43,92,59,30.

Is it right?

Was it helpful?

Solution

Given this updated tree, your preorder traversal is correct.

Your inorder traversal, though, is incorrect. As a hint, doing an inorder traversal of a binary tree always lists the values off in sorted order.

Finally, your postorder traversal is incorrect. The value 59 won't be produced until after all of the nodes in its two subtrees are produced, so it should come second-to-last. Using this fact, try seeing if you can come up with the correct answer.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top