Binary Search trees help.

So I have am having trouble understanding BST's especially preorder, post order, in order traversals. If I have something like this:

a tree

the inorder traversal will be left-root-right: 4,9,5,6,7,8? my thought process here is that each group of three numbers will be in a lef-root-right fashion: (4,9) is left of (5) and (6,7,8) is right of (5). and since (4,9) side has no left node then it is technically (null,4,9) and (6,7,8) is broken down lef-root-right if you examine it by itself.

using the same logic the pre order traversal will be root-left-right: 5, 4,9,7,6,8? or each tree broken down like (5)(4,null,9)(7,6,8)

the post order traversal will be left-right-root : (null,9,4) (6,8,7)(5) or 9,4,6,8,7,5

Am I on the right track here????

edit: I don't think i can format this BST in code very well so I made a stick diagram.

Posted Aug 17, 2017, 7:59 PM UTC · edited

13
Loading comments…