A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Binary Trees

College Depth 83 in the knowledge graph ☐ I know this ☆ Set as goal
268topics build on this
434prerequisites beneath it
See this on the map →
Linked ListsRecursion Basics+2 more→→B-Trees and Multi-Way Search TreesBinary Search Trees+4 more
binary-tree nodes root leaf height

Core Idea

A binary tree is a hierarchical data structure where each node has at most two children, called the left and right child. The tree starts at a root node; nodes with no children are leaves. Important properties include height (the longest root-to-leaf path), completeness (all levels fully filled except possibly the last), and balance (heights of left and right subtrees differ by at most a constant). Binary trees form the foundation for binary search trees, heaps, and expression parsers.

How It's Best Learned

Implement a BinaryTree class with Node objects containing left, right, and value fields. Draw many tree examples and practice identifying height, depth of specific nodes, and whether a tree is complete or balanced before touching code.

Common Misconceptions

Explainer

You've already worked with linked lists — chains of nodes connected by pointers, where each node points to the next. A binary tree generalizes this idea: instead of each node having one "next" pointer, each node has up to two child pointers, called left and right. This branching structure creates a hierarchy rather than a sequence, and that hierarchy is what makes binary trees powerful. The topmost node is the root (the entry point to the tree), and nodes with no children are called leaves (the endpoints).

To build intuition, think of a family tree or an organizational chart. The CEO sits at the root, with two direct reports below, each of whom has their own reports. The depth of any person is how many levels down from the CEO they sit — the CEO has depth 0, direct reports have depth 1, and so on. The height of the tree is the depth of the deepest node. These structural properties matter because they determine performance: most binary tree operations (searching, inserting, traversing) visit nodes along a path from root to leaf, so the height of the tree directly controls how long these operations take.

The shape of a binary tree matters enormously. A balanced binary tree keeps its height close to log₂(n), where n is the number of nodes — because each level doubles the number of nodes, you only need about 20 levels to store a million nodes. But a degenerate tree — where every node has only one child — looks exactly like a linked list, with height n. The difference between O(log n) and O(n) operations is the central motivation for balanced variants like AVL trees and red-black trees, which you'll encounter soon. Two other shape categories are important: a full binary tree is one where every node has either 0 or 2 children (never just 1), and a complete binary tree fills every level fully from left to right, with the possible exception of the last level.

Your recursion prerequisite is essential here because binary trees are inherently recursive structures. Every node is the root of its own subtree, and its left and right children are roots of smaller subtrees. This means nearly every binary tree algorithm — computing height, counting nodes, checking balance — follows the same recursive pattern: solve the problem for the left subtree, solve it for the right subtree, then combine the results. For example, the height of a tree is 1 + max(height of left subtree, height of right subtree), with a base case of -1 for an empty tree. Once you see this pattern, binary tree problems become exercises in recursive decomposition, and the data structure serves as the foundation for search trees, heaps, expression parsers, and many other structures you'll build next.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Conditional Statements → Defining and Calling Functions → Functions: Decomposing Problems → Function Parameters and Argument Passing → Return Values → Variable Scope → Introduction to Classes → Objects and Instances → Methods and Attributes → Algorithm Design Basics → Tree Structure and Node Properties → Binary Trees

Longest path: 84 steps · 434 total prerequisite topics

Prerequisites (4)

Leads To (6)