#700

Search in a Binary Search Tree

Easy BST walk

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Find the node with a given value in a BST and return its subtree, or null.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: find the node with a value.

Why this works: smaller → go left, bigger → go right. Never search both sides.

Example: find 2 in 4 (2 (1, 3), 7)

2 < 4 → left → found 2

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Searching both subtrees like an ordinary binary tree — that throws away the BST advantage.

Solve on LeetCode ↗
Complexity
  • Time: O(h).
  • Space: O(1) iterative.
Topic: Binary Search Trees
🎬 Episodes 61–63: video coming soon