1. Array
Start your learning journey by understanding the most fundamental data structure.
2. Singly Linked List
Learn in-depth the most fundamental data structure in a programmer's life
6. Queue
Learn about the data structure that powers CPU and disk scheduling algorithms
7. Binary Tree
Learn all about the most critical data structure in computer science
What you will learn
How a binary tree maps onto an array and onto a linked-list representation
Recursive and iterative preorder, inorder, postorder, and level order traversal
The four state-flow patterns: stateless and stateful preorder and postorder
Root-to-leaf path traversal in both stateless and stateful forms
Level order traversal in row-major and column-major orderings
Lowest common ancestor and simultaneous traversal across two trees
Why this course
Preorder, inorder, postorder. The three traversal definitions live in textbook glossaries and resurface in interview questions as the wrong tool every time. The real question a tree problem is asking is rarely which traversal name to pick. It is which state to thread down the tree on the way in, and which result to aggregate back up on the way out. Once you frame the problem that way, the choice of traversal becomes almost incidental.
This course rebuilds your understanding of binary trees by walking through both representations, both traversal mechanics, and the ten state-flow patterns that cover almost every tree question you will see in a coding interview. You finish with a mix-traversal practice set where the pattern is no longer announced by the section heading.
What you'll learn
- How a binary tree maps onto an array and onto a linked-list representation.
- Recursive and iterative preorder, inorder, postorder, and level order traversal.
- The four state-flow patterns: stateless and stateful preorder and postorder.
- Root-to-leaf path traversal in both stateless and stateful forms.
- Level order traversal in row-major and column-major orderings.
- Lowest common ancestor and simultaneous traversal across two trees.
Requirements
The course assumes you can read code in any mainstream language and have written at least one recursive function before.
- Comfort writing loops, conditionals, and functions in at least one language.
- Familiarity with basic Big-O notation (O(N), O(log N), O(h)).
- Some prior exposure to recursion. The Recursion course is a good warm-up if it still feels slippery.
Overview
A binary tree is a hierarchical structure where each node connects to at most two children. It is the shape behind HTML DOM trees, file systems, expression parsers, decision trees, and the index pages of every database. Once you can see how a recursive call frame moves through that shape, almost every tree problem becomes a question of which traversal carries which piece of state.
Representation of a binary tree
This course covers both halves of the problem: how the data structure actually works in array and linked-list form, and how to recognise which of the ten traversal patterns a given problem fits into.
Fundamentals
The course opens with the structural vocabulary you need to talk about a tree precisely: root, leaf, internal node, degree, siblings, path, subtree, level, depth, and height. Once those terms are pinned down, the differences between full, complete, perfect, and skew trees stop being trivia and become a quick visual check on any input.
From there the course covers both implementations side by side. The array form encodes the tree by index arithmetic, so the left child of arr[i] sits at arr[2*i + 1]. The linked-list form gives each node explicit left and right pointers. Each implementation has a different cost profile, and you trace which problems prefer which representation before either traversal pattern shows up.
The traversal mechanics come next. You first implement preorder, inorder, and postorder recursively, watching how the call stack visits each node in O(N) time and O(h) space. You then re-implement each one iteratively with an explicit stack, because real trees can be tall enough to overflow the recursion stack and a working engineer needs both versions in hand. The fundamentals close with two construction problems (rebuilding a tree from preorder and inorder, or from postorder and inorder) and the five insertion variants every tree implementation needs.
Problem solving
After the implementations and traversals, the rest of the course is patterns. Almost every tree question you will see in an interview reduces to one of ten state-flow templates. Read the problem, name the state-flow shape, and the recursion that follows is mechanical.
levelSize, in O(N) time. Level Sum, Deepest Leaves Sum, Complete Binary Tree, Zigzag Traversal, Cousin Check.Each pattern is taught in three layers. First an Understanding lesson explains the technique on a problem where the state flow is obvious. Then an Identifying lesson teaches you the markers that flag the template on first read: the type of question being asked, the shape of the return value, the state that has to travel with the recursion. Then four to seven problems give you progressively harder applications. The course ends with a mix-traversal practice section where the pattern is no longer named by the section heading and you have to spot it yourself.
How this course is different
Most binary tree material on the internet either treats the topic as one chapter of recursion or jumps straight into LeetCode-style problem dumps. This course covers both.
Who this course is for
The course suits anyone who needs to actually understand binary trees rather than guess at which traversal name to write down.
- New programmers who can build a linked list but have not yet thought about a node with two pointers instead of one.
- Self-taught and bootcamp graduates who can name preorder, inorder, and postorder but cannot tell which one a new problem needs.
- Working developers who navigate JSON ASTs, parse trees, or DOM trees day to day and want to formalise what they already use by intuition.
- Engineers preparing for FAANG and Big Tech interviews where tree questions appear in nearly every onsite loop.
- Returning engineers who learned trees years ago in school and want a clean refresher with the iterative traversals they never use day to day.
- Anyone who has memorised a tree solution but cannot articulate which traversal it uses or why.
Continue your DSA journey
Binary trees connect to most of the rest of the curriculum, both as a prerequisite and as a generalisation. After this course, the natural next steps depend on where you want to go
- Stack: Iterative tree traversal is a stack-walk problem. The stack course goes deeper on stack mechanics and on patterns like next-closest that compose naturally with iterative inorder.
- Queue: Level order traversal lives on a queue. Understanding queue mechanics speeds up the column-order and view-based patterns in this course.
- Binary search tree: A BST is a binary tree with an ordering invariant. Every BST pattern reuses the traversal patterns you learn here, so taking the BST course right after this one is the cleanest progression.
- Graph: A tree is a connected acyclic graph. The DFS and BFS techniques generalise directly to graphs once you add a visited set, and the level order traversal you saw here is the same machine as BFS shortest-path.
- Recursion: Tree problems are recursion problems with a particular base case. Recursion teaches the call-stack model itself, so it pairs well as a deeper prerequisite if any of the stateful patterns still feel mechanical rather than intuitive.
- Backtracking: Backtracking lives inside the stateful root-to-leaf pattern you learn in this course, applied to decision trees rather than concrete data trees. The push-on-entry, pop-on-backtrack mechanic is identical.
Frequently asked questions
traverse(node.left) pushes a frame, and the runtime pops it when the call returns. An iterative traversal uses an explicit stack (or queue, for level order) that you manage yourself. The two have the same O(N) time and O(h) space complexity, but iterative versions never overflow on a tall tree because the stack lives on the heap. Real interviewers ask for both because production systems sometimes need the iterative form.2i + 1 and 2i + 2. A perfect binary tree is both full and complete, every internal node has two children and every leaf sits at the same depth. A perfect tree of height h always holds exactly 2^(h+1) - 1 nodes. The three terms describe shape, not value ordering, so the same tree can be all three (a perfect tree is also full and complete) or none of them.