SOLID STATE PRESS
← Back to catalog
Recursion and Recursive Data Structures cover
Coming soon
Coming soon to Amazon
This title is in our publishing queue.
Browse available titles
Computer Science

Recursion and Recursive Data Structures

Base Cases, Call Stacks, and Recursive Tree Traversal — A TLDR Primer

Recursion shows up in nearly every computer science course, and it trips up almost every student the first time. The idea that a function can call itself feels circular, even illegal — and then trees and linked lists arrive and the confusion compounds. If you have a CS exam coming up, a data structures assignment due, or you just need to finally understand what the call stack is actually doing, this guide is written for you.

**TLDR: Recursion and Recursive Data Structures** covers everything a high school or early college student needs to get comfortable with the topic. You'll start with how recursive functions work and how to read the call stack like a mental movie. From there, you'll work through factorial, merge sort, and binary search — concrete, numbered examples in pseudocode and Python-style syntax. Then the guide moves into the data structures that make recursion click: linked lists defined as a node plus a smaller list, and binary trees where recursive traversal stops feeling like magic and starts feeling obvious.

The final section is honest about tradeoffs — when recursion is the right tool, when iteration wins, and how stack limits and the Fibonacci pitfall motivate memoization. Each concept is introduced with a plain-English definition before any code appears.

This is a focused primer, not a textbook. No filler, no padding — just the core ideas, worked examples, and the conceptual clarity you need to walk into class or an ap computer science exam on recursion with confidence.

Grab it, read it once, and understand recursion.

What you'll learn
  • Understand what recursion is and how a function call stack executes recursive calls
  • Identify base cases and recursive cases, and write recursive functions correctly
  • Trace recursive execution by hand and reason about termination
  • Define and manipulate recursive data structures like linked lists and binary trees
  • Recognize when recursion is the right tool and when iteration or memoization is better
What's inside
  1. 1. What Recursion Actually Is
    Introduces recursion as solving a problem by reducing it to a smaller instance of the same problem, with the call stack as the mental model.
  2. 2. Writing Your First Recursive Functions
    Walks through factorial, sum-of-list, and power functions, showing how to choose a base case and shrink the input each call.
  3. 3. Recursive Thinking: Divide, Conquer, and Combine
    Covers the divide-and-conquer pattern with binary search and merge sort, plus the Fibonacci pitfall that motivates memoization.
  4. 4. Recursive Data Structures: Linked Lists
    Defines linked lists as a recursive structure (a node plus a smaller list) and implements length, search, and reverse recursively.
  5. 5. Trees and Recursive Traversal
    Introduces binary trees, binary search trees, and the three classic traversals, showing why trees are where recursion really pays off.
  6. 6. When to Use Recursion (and When Not To)
    Compares recursion with iteration, discusses tail calls, stack limits, and gives heuristics for choosing the right approach.
Published by Solid State Press
Recursion and Recursive Data Structures cover
TLDR STUDY GUIDES

Recursion and Recursive Data Structures

Base Cases, Call Stacks, and Recursive Tree Traversal — A TLDR Primer
Solid State Press

Contents

  1. 1 What Recursion Actually Is
  2. 2 Writing Your First Recursive Functions
  3. 3 Recursive Thinking: Divide, Conquer, and Combine
  4. 4 Recursive Data Structures: Linked Lists
  5. 5 Trees and Recursive Traversal
  6. 6 When to Use Recursion (and When Not To)
Chapter 1

What Recursion Actually Is

A function that calls itself sounds like it should cause an infinite loop — and it will, if you write it wrong. But done right, it's one of the most powerful ideas in programming: solve a problem by reducing it to a smaller version of the same problem, then let that smaller version reduce itself further, until you hit a case so simple it needs no recursion at all.

That's the whole idea. Everything else in this book is a consequence of it.

A concrete image

Imagine you're standing in a long line and you want to know what position you're in, but you can't see the front. You turn to the person ahead of you and ask, "What's your position?" They don't know either, so they ask the person ahead of them, and so on down the line. Eventually someone reaches the front: "I'm number 1." That person reports back to the one behind them, who adds 1 and reports back, and so on until the answer travels back to you.

Every person in that line is solving the same problem — "what's my position?" — by delegating a smaller version of it to someone else and then doing one unit of work on the result. That's recursion.

Base case and recursive case

Every correct recursive process has exactly two kinds of steps.

The base case is the version of the problem simple enough to answer directly, without any further delegation. In the line example, the person at the front is the base case: position 1, no need to ask anyone else.

The recursive case is every other situation, where you reduce the problem — make it strictly smaller — and call the same process again. In the line: "I don't know my position directly, but I know it's one more than the position of the person ahead of me."

A common mistake is to forget the base case entirely, or to write a recursive case that doesn't actually make the problem smaller. Either error produces infinite recursion: the function keeps calling itself forever (or until the computer runs out of memory and crashes).

About This Book

If you're taking AP Computer Science A and recursion finally broke your brain, or you're a high school student who needs to learn recursive functions for a class project, or you're a college freshman dropped into an intro to computer science course without much background — this book is for you. Parents tutoring a student through a tricky unit will find it useful too.

This primer covers everything a student needs: how recursive functions actually work, the base-case/recursive-case pattern, divide and conquer algorithms, and the self-referential data structures they operate on — linked lists, binary trees, and recursive traversal. It doubles as a Python recursion beginner study guide, with every concept shown in clean, readable code. A concise overview with no filler.

Read it straight through — the chapters build on each other. Work every example before checking the solution, then hit the problem set at the end. That sequence is what moves recursion from "I sort of get it" to something you can actually use on an exam or in code.

Keep reading

You've read the first half of Chapter 1. The complete book covers 6 chapters in roughly fifteen pages — readable in one sitting.

Coming soon to Amazon