Question

What does it mean to build a binary search tree by inserting values from left to right starting from an empty tree? The "left to right" part confuses me..I know how to build one by normally inserting values from the top..but what does this mean?

Could anyone please explain how to insert values from left to right with an example? An example would be really helpful..please and thank you.

I have a set of values S = {4,5,6,7,8}, and I'm supposed to build a binary search tree by inserting values "from left to right" which forces it to have some height, some depth. etc. I've already done this question but I'm not sure if I'm supposed to build the tree in some specific manner since it mentions that left to right part.

Was it helpful?

Solution

In the context of this question, I believe the term "from the left to the right" means that you're supposed to insert the values in S into the tree in the order in which they're listed in S, namely, in the order 4, 5, 6, 7, 8. The shape of the tree depends on the insertion order, so if there's a specific result they're looking for when grading they need to specify what order they're added in.

Hope this helps!

OTHER TIPS

I don't think the idea of "inserting from left to right" is valid, because there's never a tree with no root but a left child. In other words, the first insert on an empty tree most definitely becomes the root of the tree. I'd double check on the wording of the question with the person who presented this idea.

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