Learning order

1. Recursion

Premium

Take a deep dive into one of the most intuitive programming paradigm

Show Index

2. Backtracking

Premium

Learn about the ultimate recursive brute force technique

Show Index

3. Sorting

Premium

Learn all about algorithms to sort data blazingly fast

Show Index

4. Searching

Premium

Learn about the algorithms that speed up your searches exponentially

Show Index

5. Dynamic Programming

Premium

Learn the most powerful optimization for recursive problems

(Early Access)

Show Index

6. Bit Manipulation

Premium

Learn about the fastest ways to manipulate data

(Early Access)

Show Index

What you will learn

How a program is laid out in memory across heap, stack, static, and code segments

How a stack frame stores arguments, locals, the return value, and the return address

The three building blocks of every recursion: structure, base case, and recursive relation

Head and tail recursion as distinct templates, with passing by value versus reference

Multiple recursion: branch into k calls and derive O(k^N) time from the recursion tree

Multidimensional recursion: state as n dimensions with O(k^(n·N)) complexity

Why this course

Tracing recursion in your head is how most people first try to understand it, and it stops working four levels deep. The frames pile up faster than the brain can hold them, the deeper calls produce values that never connect back to the original problem, and the only thing left is hoping the base case happens to be right. Replacing the trace with a model of what the call stack actually does in memory is what makes recursion clickable.

This course replaces tracing with a model. You start with how memory is partitioned across heap, stack, static, and code segments, watch stack frames push and pop in LIFO order, then build recursion as the natural consequence of a function calling itself. After that you work through the four patterns (head, tail, multiple, and multidimensional) that account for almost every recursive interview problem.

Requirements

The course assumes you can write basic code in one mainstream language. No prior data structures experience is required.

  • Comfort with functions, loops, and conditionals in at least one language.
  • Familiarity with basic Big-O notation (O(N), O(log N), O(2^N)).
  • A willingness to think about what a function call costs in memory, not only in syntax.

Overview

Recursion is a function that solves a problem by calling itself on a smaller version of the same problem. It is the only natural way to express problems whose structure repeats at smaller scales: factorials, Fibonacci, tree traversals, divide-and-conquer sorts, every backtracking puzzle, almost every dynamic-programming recurrence. The same code mechanism (a function calling itself) compiles down to repeated call and ret instructions, and the same memory mechanism (a fixed-size stack region) bounds how deep that recursion can go. Recursion is not a trick. It is the shape of an entire family of algorithms.

Representation of recursion

The course covers both halves of the problem: how the call stack runs a recursive function in memory, and how to recognise which of the four standard recursion patterns a given problem fits into.

Fundamentals

The course opens with the memory model. A running process is divided into four regions: a code segment holding compiled instructions, a static segment for globals, a heap that grows on demand, and a stack that holds one frame per active function call. Each call pushes a stack frame containing the stack pointer, frame pointer, local variables, arguments, return value, and return address. When a function returns, its frame is popped and execution resumes at the return address inside the caller's frame. The course traces this for compiled languages (C, C++) and for interpreted ones (Python, JavaScript), so you can see what happens under both the compilation pipeline and the tokenise / parse / bytecode-execute pipeline that an interpreter follows.

From there the course builds nested function calls. You see why the topmost frame is always the function currently executing, why a stack overflow happens when call depth or huge local arrays exhaust the fixed stack region the OS allocates per process, and why these failures are not always obvious from reading the source. By the time the recursion section begins, the call stack is no longer a black box.

Recursion itself is introduced through the ATM queue example. A person at the back of the queue asks the person ahead what position they hold, adds one, and returns it. The first person already knows their position is one. That single story contains every component the course later names: a recursive structure (each person asks the one ahead), a base case (the first person), and a recursive relation (position = ahead.position + 1). From there you implement the same idea as a self-calling function, learn when to pass arguments by value versus reference, and draw the recursion tree that every later pattern analysis depends on.

Problem solving

After the fundamentals come the patterns. Almost every recursive problem you will see in an interview fits one of four templates, and identifying which template a problem fits is the actual work. Once you have done that, the implementation writes itself from the template.

The 4 recursion patterns you'll master
Head recursion
Place the recursive call at the top of the function and build the answer bottom-up as the stack unwinds, running in O(N) time and O(N) stack space. Forward Sequence, Calculate Factorial, Sum of Digits, Reverse a Queue.
Tail recursion
Place the recursive call last and carry the running answer forward through an aggregate parameter, so the base case returns the final result top-down in O(N) time. Reverse Sequence, Search Element, Is Palindrome, Reverse a List.
Multiple recursion
Branch each step into k recursive calls and aggregate their results, producing the O(k^N) time complexity that a recursion tree makes obvious. Fibonacci Number, Zigzag Sequence, Climb Stairs, Catalan Number.
Multidimensional recursion
Define state as n dimension values, explore allowed shifts to multiple base cases, and derive O(k^(n·N)) complexity from the multidimensional recursion tree. Binomial Coefficient, Lattice Paths, Ackermann Function, Egg Dropping.

Each pattern is taught in three layers. First an Understanding lesson walks the technique through a problem where the pattern is obvious. Then an Identifying lesson teaches you the signals (the shape of the recursive equation, the number of branches, the dimensionality of the state) that tell you a new problem fits the template. Then four problems give you progressively harder applications. The course finishes on multidimensional recursion through Egg Dropping, the classic puzzle that sets up the two-dimensional recurrence you will meet again in the dynamic-programming course.

How this course is different

Most recursion material on the internet either skips the call stack or skips the patterns. This course closes both gaps.

Most DSA resources
This course
Treat recursion as a one-line topic before jumping to "100 recursion problems".
Starts with how memory is partitioned and how a stack frame is laid out, so every recursive call has a concrete picture behind it.
Skip the call stack entirely, leaving you no way to reason about why a solution stack-overflows on certain inputs.
Treats head, tail, multiple, and multidimensional recursion as four distinct templates, with explicit identification signals for each.
Teach recursion through a couple of isolated examples (factorial, Fibonacci) without naming the underlying patterns.
Derives complexity from the recursion tree rather than asserting it, so O(k^N) and O(k^(n·N)) stop being memorised facts.
Conflate head and tail recursion as "the same thing with the line in a different place".
Covers passing arguments by value versus reference, and how the choice changes what the answer means at each frame.
Stop at one-dimensional recurrences, so multidimensional problems like lattice paths and egg dropping feel like a different topic.
Connects directly into backtracking, dynamic programming, tree traversal, and graph DFS, the four topics that depend most on recursion.

Who this course is for

The course suits anyone who needs to write recursive code with confidence rather than guess at base cases.

  • New programmers who can write loops but freeze the moment a function calls itself.
  • Self-taught and bootcamp graduates who can solve recursive problems they have seen before but cannot derive a recursion from a problem they have not.
  • Working developers who use recursion through library code (tree walks, JSON traversal) but cannot reason about the call depth a function will reach on real input.
  • Engineers preparing for FAANG and Big Tech interviews, where recursion sits underneath every tree, graph, backtracking, and dynamic programming question.
  • Returning engineers who learned recursion in university through factorial and Fibonacci and want a refresher that names the patterns properly.
  • Anyone who can write a recursive function but cannot explain why its base case is correct.

Continue your DSA journey

Recursion is the prerequisite for half of the curriculum. After this course, the natural next steps depend on which family of problems you want to tackle.

  • Singly linked list: Linked-list problems are a clean playground for head and tail recursion. Reversing a list, finding the kth-from-last node, and merging two sorted lists all collapse into one of the templates in this course.
  • Binary tree: A binary tree traversal is multiple recursion on the children of each node. Once head, tail, and multiple recursion click, recursive preorder, inorder, and postorder traversal stop feeling memorised and become consequences of where the work sits relative to the recursive calls.
  • Graph: Depth-first search on a graph is recursion with a visited set. The cycle-detection and topological-sort algorithms in the graph course rely on exactly the head and tail recursion templates taught here, with one extra piece of bookkeeping for already-visited nodes.
  • Backtracking: Backtracking is recursion plus an unmark-on-exit step. Every backtracking problem (permutations, combinations, N-queens, sudoku) is a multiple-recursion problem whose state is mutated before each branch and restored after. The four templates in this course transfer directly, with one additional mechanic.
  • Dynamic programming: Every DP problem starts life as a recursive recurrence. Memoisation is multiple or multidimensional recursion with a cache; tabulation is the same recurrence unrolled. The recursion trees you learn to draw in this course are the diagrams you optimise in the DP course.

Frequently asked questions

Code examples use Python for readability, but every concept (stack frames, base cases, recursive relations, recursion trees) is language-agnostic. The course shows how a stack frame is laid out in a compiled language like C and how Python and JavaScript run the same recursion through their interpreters, so you can carry the model into whichever language you write at work.
Yes. The course starts from how a program sits in memory and only introduces recursion after the call stack is clear. If you can write a function and read Big-O notation like O(N) and O(2^N), you have everything you need. Most beginners find recursion easier once the stack frames stop being magic.
There are around 19 lessons and 16 problems across four patterns, plus the introduction to the memory model and the call stack. Most learners finish the lessons in 8 to 12 hours and need another 10 to 18 hours for the problems, depending on how much recursion they have written before.
Recursion is the technique that underpins tree, graph, backtracking, and dynamic-programming questions, which together make up a large share of any onsite loop. The four patterns covered (head, tail, multiple, multidimensional) cover the templates these later questions reduce to, so you will recognise the recursive shape on first read rather than reaching for a half-remembered example.
LeetCode shows you recursive problems one at a time with no grouping, so the same template looks new every time you see it on a different problem. This course teaches the four templates first, then drills problems within each template so you build pattern recognition instead of memorising individual solutions.
Use recursion when the problem's structure repeats at a smaller scale, when the answer for input N depends on the answer for one or more smaller subproblems. Tree traversal, divide and conquer, backtracking, and most DP recurrences fit this shape and are natural to express recursively. Use iteration when the problem walks a sequence in a single direction without nested sub-results, like counting, summing, or in-place reversal. The deciding question is whether the algorithm needs the language runtime to track state across multiple unresolved subproblems for you. If yes, recursion is the right tool. If not, a loop is simpler and avoids stack overhead.
In head recursion, the recursive call happens first and the real work happens after it returns. Each frame waits for the deeper frame to produce a value, then combines it with local data on the way out. Computing a factorial or summing digits bottom-up is head recursion. In tail recursion, the recursive call is the last thing the function does, and an aggregate parameter carries the running answer forward into each new frame. The base case returns the final answer directly, with no work left to do on the way out. Reversing a sequence or searching a list with a moving index is tail recursion. The difference matters because tail recursion can be optimised into a loop in some languages (tail-call optimisation), while head recursion always keeps O(N) stack frames open until the base case is reached.
Yes. Once you finish all lessons and the problems, codeintuition issues a shareable certificate you can post to LinkedIn or attach to a job application.