Trees

Problem shape

Beginner
8
3
10
1
6
9
14
Core idea

Use the binary-search-tree ordering to move left or right from each node.

Step 1 / 5
Problem shape
Current lesson

BST Search Lab

Trees Beginner

BST Search

Welcome to the BST Search algorithm lab. Use the binary-search-tree ordering to move left or right from each node. Use it when: Use when values are organized in a balanced search tree. The time complexity is O(h), and the space complexity is O(1). The pseudocode is: node = root while node exists if target == node.value return node if target < node.value node = node.left else node = node.right As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(h)

Space

O(1)

Pseudocode

node = root
while node exists
  if target == node.value return node
  if target < node.value node = node.left
  else node = node.right
Open deeper structure lesson
1.0x