Skip to content
BENIBIX Learn

Binary Tree

Development🧮 Algorithms & Data StructuresData Structures

Also known as Binary Trees

A tree where each node has at most two children, a left and a right.

Think of it like

Think of it like a path that splits in two at each fork. It never splits in three.

Example

Lucy draws a binary tree for a game of twenty questions. Each yes or no answer goes left or right to the next question.

Why it matters

It is the shape behind binary search trees, heaps and many indexes.

Definition

A binary tree is a tree where each node has at most two children, called left and right. That simple rule makes it easy to store and to walk through. Many faster structures are built on it, like the binary search tree and the heap. A balanced binary tree with a million nodes is only about 20 levels deep. That depth is why searches in one can be so quick.

Common mistake

Thinking every binary tree is sorted. Only a search tree keeps its values in order.

Key takeaways

  1. 1
    Two children at most. Left and right.
  2. 2
    Shallow when balanced. About 20 levels for a million.
  3. 3
    A base for others. Search trees and heaps.