liveBook · Manning

Chapter 3: Recursion

What you will learn in chapter 3 of Grokking Algorithms, Second Edition

The chapter introduces recursion’s importance, recommends hands-on ways to learn it, and defines pseudocode.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces recursion’s importance, recommends hands-on ways to learn it, and defines pseudocode.

Key terms: recursion, divide-and-conquer strategy, recursive functions, factorial, pseudocode

3.1 Recursion

The section introduces recursion through a search for a key in nested boxes and compares it with a loop-based approach.

Key terms: recursion, function calls itself, while loop, pile, performance

3.2 Base case and recursive case

This section explains why a recursive function needs a base case to stop calling itself.

Key terms: base case, recursive case, infinite loop

3.3 The stack

The section introduces a stack through a sticky-note to-do list, explaining how push and pop operate at its top.

Key terms: stack, push, pop

3.4 The call stack

Explains how the call stack stores each function call’s variables and lets a paused caller resume after another function returns.

Key terms: call stack, function call, variables

3.5 The call stack with recursion

This section uses factorial and a box-search example to show how recursive calls use the call stack to preserve unfinished work, and why that convenience costs memory.

Key terms: call stack, fact, x, pile of boxes, half-completed function calls, memory, stack, loop, tail recursion

3.6 Recap

Recaps recursion’s two cases, stack operations, and how the call stack uses memory.

Key terms: recursion, base case, recursive case, stack, push, pop, call stack, memory

Where this is used later

Concepts explained in this chapter

← Chapter 2: Selection sort Chapter 4: Quicksort →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.