Course contentsShow
← Computer Science
Lesson 505 of 2,87212. Binary Search TreesFree lesson

Finding Minimum and Maximum Values

Locate the minimum value by following left children and maximum by following right children to leaf nodes.

Finding Minimum and Maximum Values

You'll learn how to locate the smallest and largest values in a Binary Search Tree by following simple directional rules.

The Core Idea

In a Binary Search Tree, finding the minimum or maximum value is remarkably straightforward thanks to the BST invariant (left children < parent < right children). To find the minimum value, start at the root and keep following left children until you reach a node with no left child—that's your minimum. To find the maximum value, do the opposite: keep following right children until you reach a node with no right child.

Why This Works

Remember the BST property: all values in the left subtree are smaller, and all values in the right subtree are larger. This means:

  • The smallest value can't possibly be to the right of any node
  • The largest value can't possibly be to the left of any node

Think of it like walking down a hallway where left doors lead to smaller rooms and right doors lead to larger rooms. To find the smallest room, you'd keep going left until there are no more left doors!

Simple Patterns

Minimum: Go left until you can't anymore
Maximum: Go right until you can't anymore

Both operations take O(h) time where h is the height of the tree—you're just following one path from root to leaf. In a balanced BST, this is O(log n), but in a worst-case unbalanced tree, it could be O(n).

Key Takeaway: In a BST, the minimum value is found by following left children to a leaf, and the maximum by following right children to a leaf—both leveraging the BST's ordered structure.