Learning order

1. Array

Free

Start your learning journey by understanding the most fundamental data structure.

Show Index

2. Singly Linked List

Free

Learn in-depth the most fundamental data structure in a programmer's life

Show Index

3. Doubly Linked List

Premium

Learn about the extension of the singly linked list that powers stacks and queues

Show Index

4. Hash Table

Premium

Learn how applications deal with key value mappings efficiently

Show Index

5. Stack

Premium

The data structure behind recursion, memory management, and much more

Show Index

6. Queue

Premium

Learn about the data structure that powers CPU and disk scheduling algorithms

Show Index

7. Binary Tree

Premium

Learn all about the most critical data structure in computer science

Show Index

8. Binary Search Tree

Premium

Learn about the most critical search data structure in computer science

Show Index

9. Heap

Premium

Learn all how a tree can be used as a priority queue

Show Index

10. Graph

Premium

Learn about the most dynamic data structure in computer science

Show Index

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.

The 10 binary tree patterns you'll master
Preorder traversal (stateless)
Visits node, left, right, passing a separate aggregate copy from each parent down to its children, solving root-anchored sums in O(N) time. Sum of Path, Depth Assignment, Concatenated Path, Increasing Path.
Preorder traversal (stateful)
Threads shared state down the recursion so each node updates a running structure on entry and reverts it on exit, in O(N) time with O(h) stack. Duplicates in Path, Second Minimum, Left View, Right View.
Postorder traversal (stateless)
Recurses left, then right, then combines the two child return values into a single result at each node, the shape behind height, diameter, and most "is this tree X" checks. Sum of Leaves, Height of Binary Tree, Maximum Path Sum, Full Binary Tree, Perfect Binary Tree, Collect Leaves.
Postorder traversal (stateful)
Returns aggregated data from each subtree while updating shared state at every parent, the workhorse of diameter, distribute-coins, and path-sum-count problems. Diameter of Tree, Descendants Sum Count, Distribute Coins, Most Frequent Subtree Sum, Longest Monotonic Path, Monotonic Subtree Count, Path Sum Count.
Root to leaf path (stateless)
Carries a copy of the running path or its aggregate from root down to each leaf, recording the result whenever a leaf is reached. Root To Leaf Path, Binary Summation of Tree, Even Path, Odd Count.
Root to leaf path (stateful)
Shares one path buffer across the whole traversal, pushing on entry and popping on backtrack to reuse memory across all root-to-leaf walks. Root To Leaf Paths, Equal Paths, Duplicate Paths, Prefix Paths.
Level order traversal
Queue-based breadth-first walk that aggregates one level at a time using a nested loop driven by the current levelSize, in O(N) time. Level Sum, Deepest Leaves Sum, Complete Binary Tree, Zigzag Traversal, Cousin Check.
Level order traversal (columns)
Augments BFS with a column index per node so siblings inherit their parent's coordinate, producing top, bottom, vertical, and diagonal views in O(N log N) time. Top View, Bottom View, Vertical Traversal, Diagonal Traversal.
Lowest common ancestor
Postorder recursion that returns each subtree's LCA up the call stack and merges two results at every parent, settling the answer in one pass in O(N) time. Lowest Common Ancestor, Lowest Common Ancestor II, Random Lowest Common Ancestor, Deepest Lowest Common Ancestor, Distance Between Nodes.
Simultaneous traversal
Recurses two trees together, comparing or merging corresponding nodes in lockstep, the standard approach for identical-tree, mirror, subtree, and merge questions in O(N) time. Identical Trees, Symmetry Detection, Subtree Detection, Merge Trees.

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.

Most DSA resources
This course
âś—Treat binary trees as "the recursive thing" and never show the iterative traversals real interviewers ask about.
✓Separates state flow into stateless and stateful preorder and postorder, so each variation has its own muscle memory.
âś—Present preorder, inorder, and postorder as definitions to memorise rather than state-flow patterns to recognise.
✓Covers both recursive and iterative versions of every traversal, because tall trees overflow the call stack in practice.
âś—Mix binary trees and BSTs into the same chapter, so it never becomes clear which property each problem depends on.
✓Treats lowest common ancestor as a postorder pattern with one return shape, not a one-off algorithm to memorise.
âś—Teach lowest common ancestor as one specific algorithm rather than a postorder pattern that generalises across questions.
✓Covers level order traversal in both row-major and column-major forms, including top, bottom, vertical, and diagonal views.
âś—Skip column-order traversal entirely, leaving top-view, bottom-view, and diagonal traversal as surprises in the interview.
✓Closes with a mix-traversal practice set where the section heading no longer gives the pattern away.

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

Code examples use Python for readability, but every concept (tree representation, traversal mechanics, state flow) is language-agnostic. The course shows how a node struct translates to C, Java, JavaScript, and Python, and explains where the differences matter.
Yes, provided you have written at least one recursive function before. The course defines every tree term from scratch and builds the traversals layer by layer. If recursion itself is still new, start with the Recursion course first.
There are around 47 lessons and 62 problems across 10 patterns plus the construction and insertion sections. Most learners finish the lessons in 14 to 19 hours and need another 25 to 35 hours to solve the problems, depending on prior experience with recursion.
The patterns covered (preorder, postorder, root-to-leaf, level order, lowest common ancestor, simultaneous traversal) account for almost every tree question asked in real onsite loops. You will recognise the state-flow template on first read of the problem.
LeetCode shows you tree problems one at a time with no grouping. This course teaches the ten state-flow templates first, then drills problems within each template so you build pattern recognition instead of memorising 200 individual solutions.
A recursive traversal lets the language runtime manage the call stack: each call to 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.
A full binary tree is one where every internal node has exactly two children. A node has zero or two children, never one. A complete binary tree fills every level except possibly the last, and the last level is filled left to right with no gaps. This is the shape a heap maintains, which is why a heap can live in a contiguous array indexed by 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.
Yes. Once you finish all lessons, problems, and the mix-traversal practice set, codeintuition issues a shareable certificate you can post to LinkedIn or attach to a job application.