Binary Search Tree - Postorder logic
- by daveb
I am looking at implementing code to work out binary search tree.
Before I do this I was wanting to verify my input data in postorder and preorder.
I am having trouble working out what the following numbers would be in postorder and preorder
I have the following numbers 4, 3, 14 ,8 ,1, 15, 9, 5, 13, 10, 2, 7, 6, 12, 11, that I
am intending to put into an empty binary tree in that order.
The order I arrived at for the numbers in POSTORDER is
2, 1, 6, 3, 7, 11, 12, 10, 9, 8, 13, 15, 14, 4. Have I got this right?
I was wondering if anyone here would be able to kindly verify if the postorder sequence I came up with is indeed the correct sequence for my input i.e doing left subtree, right subtree and
then root.
The order I got for pre order (Visit root, do left subtree, do right subtree) is
4, 3, 1, 2, 5, 6, 14 , 8, 7, 9, 10, 12, 11, 15, 13. I can't be certain I got this right.
Very grateful for any verification.
Many Thanks