Codacoda
Back to Academy

trees

Binary Search Tree

A Binary Search Tree (BST) is a node-based binary tree where each node has at most two children. For each node, all values in the left subtree are less than the node's value, and all values in the right subtree are greater. This property enables efficient searching, insertion, and deletion.

Use Cases

  • Implementing sorted sets and maps
  • Database indexing
  • Priority queues and scheduling

Complexity Analysis

MetricBestAverageWorst
TimeO(log n)O(log n)O(n)
SpaceO(n)

Visualization

Speed:1x
Empty treeStep 1 / 19

Implementation

Output

Click "Run Code" to see output...