Search⌘ K
AI Features

Introduction to Binary Search Trees

Explore the concept of binary search trees (BSTs), understanding their ordered structure where left children hold smaller values and right children hold larger or equal values. Learn how BSTs enable efficient search, insertion, deletion, and sorted data retrieval through inorder traversal. Discover how the shape and balance of the tree affect performance, and distinguish BSTs from general binary trees through practical examples to build a foundation for advanced tree structures.

A binary tree is a data structure where each node has at most two children: a left child and a right child.

A binary search tree (BST) is a special type of binary tree that maintains an ordering rule:

  • All values in the left subtree are smaller than the node.

  • All values in the right subtree are greater than or equal to the node.

  • This rule applies recursively to every node.

For example, if the root is ...