Skip to main content

Smaller left, larger right

A binary search tree stores keys so that every key in a node’s left subtree is smaller than that node’s key and every key in its right subtree is larger. This lets you find a key by choosing left or right at each node, without checking every node.

In the picture

  1. The root: the first key every search compares against
  2. Left child: smaller than the root, so it goes on the left
  3. Right child: larger than the root, so it goes on the right
  4. A leaf in the right subtree: larger than the root but smaller than its parent, so it hangs on that parent’s left

Examples

  • Guessing a number from 1 to 100 when each answer is "higher" or "lower" rules out half of what is left
  • Looking up a word in a paper dictionary by opening the middle and going earlier or later

Quiz: Smaller left, larger right (Age 17)

  1. In a binary search tree, which keys can appear anywhere in the left subtree of a node whose key is 50?

    • Keys smaller than 50 directly below the node, but any key deeper down
    • Only keys smaller than 50
    • Any keys, as long as the node’s direct left child is smaller than 50
  2. A binary search tree has root 50, and the root’s right child is 80. Where does a new key 60 go?

    • In the right subtree, to the left of 80
    • In the right subtree, to the right of 80
    • In the left subtree, because 60 is smaller than 80
  3. When you search for a key in a well-balanced binary search tree, roughly how many nodes do you check?

    • Every node in the tree
    • Every node on one level before moving down to the next
    • About one node per level

The answers, each with its explanation, are in the app. This lesson has left the free week, so its quiz is part of the subscription.

Get the app

Free app, optional subscription
App Store Google Play

Carry on in the app

At least one new illustrated lesson every weekday for your child’s year, with its quiz and a reminder at 6:15 pm.

Your child’s teacher does not use My Enhanced Teacher yet?

Tell them about it

Technology, Age 17