1

These values are entered into an ordered binary tree: Mercury, Venus, Earth, Mars, Jupiter, Saturn and Uranus.

The resulting binary tree is supposed to be this.

          Mercury
        /         \
    Earth         Venus
       \           /
      Jupiter   Saturn
         \        \
        Mars     Uranus

Is there any reason for this order? Shouldn't Jupiter be under the Venus branch?

1
  • The given tree is incorrect for the given insertion order - Mars should be a right child of Earth and Jupiter should be a left child of Mars because the Jupiter node won't exist when inserting Mars. See this question for the correct ordering - Binary Search Tree of Strings (before balancing). Commented Dec 12, 2013 at 22:15

1 Answer 1

1

By "ordered binary tree", I assume you mean a binary search tree. As long as the tree satisfies the following criteria:

1. The key in a node is greater than (or equal to) any key stored in its left subtree.
2. The key in a node is less than (or equal to) any key stored in its right subtree.

then the exact structure of the tree depends on the order in which the keys are added and the exact algorithm used to construct the tree.

However, you indicate that you believe that Jupiter should occur in the subtree of Venus. What is your ordering criteria? The tree you show is valid if the names are being compared alphabetically.

Sign up to request clarification or add additional context in comments.

1 Comment

I see, that I was what I am wondering if they are ordered alphabetically or just random inserted into the tree. I take it its done by alphabetical order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.