Module 6

Recursion: Concepts and Implementation

This lesson explains recursion as a programming strategy, covering base cases, recursive calls, and the call stack. Students will implement classic recursive algorithms such as factorial, Fibonacci, and recursive list traversal in JavaScript.

Topics

This module covers 7 topics. Open a topic to see its subtopics and the materials made for it.

  1. Topic 1What is Recursion?5 subtopics · 2 materials
  2. Topic 2Base Cases and Recursive Cases6 subtopics · 2 materials
  3. Topic 3The Call Stack and Recursion6 subtopics · 2 materials
  4. Topic 4Implementing Factorial with Recursion6 subtopics · 2 materials
  5. Topic 5Fibonacci Sequence Using Recursion6 subtopics · 2 materials
  6. Topic 6Recursive List Traversal6 subtopics · 2 materials
  7. Topic 7When to Use Recursion5 subtopics · 2 materials

Module Content

16 items of 3 types: Topic Detail, Topic Videos, Readings. Your instructor made most of them with CourseBuilder+, a program that uses AI to draft course material; each type says how its items were made.

Topic Detail (7)

A detailed reading for each topic, covering its subtopics in order with explanations and examples — reading only, no videos (for the reading with videos, see Topic Detail with Video). Drafted with AI from the module's topics, subtopics and learning outcomes.

  • Introduces recursion as a programming technique in which a function calls itself to break a problem into smaller instances of the same problem, and serves as a conceptual reading for learners beginning the module.

  • Explains the two essential components of any recursive function — the base case (stopping condition) and the recursive case (self-referential step) — and is used by learners to understand how to structure correct, non-infinite recursive solutions.

  • Describes how the call stack manages function execution, local data, and return addresses during recursive calls, helping learners understand the runtime mechanics and memory implications of recursion.

  • Walks through implementing the factorial function recursively, using its naturally self-referential mathematical definition to illustrate how to translate a recursive formula directly into working code.

  • Covers the recursive implementation of the Fibonacci sequence, demonstrating how a function can make two recursive calls and highlighting the resulting redundant computation as an entry point for discussing efficiency trade-offs.

  • Demonstrates how to traverse a JavaScript array recursively by splitting it into a head element and a remaining subarray, providing learners with a practical pattern for applying recursion to list-processing problems.

  • Examines the trade-offs between recursion and iterative loops, guiding learners and instructors in identifying problem types — such as tree traversal and divide-and-conquer — where recursion is most appropriate versus where iteration is preferred.

Topic Videos (8)

Videos for each topic: a short introduction to the topic, then up to three YouTube videos embedded, each with what it covers and why it is worth watching. The videos were found by an AI search of YouTube (well viewed, with captions where possible), and the page was written with AI.

  • An introductory reading that defines recursion as a problem-solving strategy in which a function calls itself on a smaller version of the same problem, using examples like factorial and list length to contrast self-referential definitions with explicit loops; learners read it first to build the conceptual vocabulary for the rest of the module.

  • A lesson breaking recursive functions into their two required parts — the base case that stops the recursion and returns a value, and the recursive case that calls the function on a smaller subproblem — which learners use to diagnose why a function recurses forever or terminates correctly.

  • An explanation of how the call stack stores one stack frame per active function call in last-in, first-out order, and how recursion makes this bookkeeping visible through stacked frames, return addresses, and local variables; instructors use it to motivate stack depth limits and stack overflow errors.

  • A worked implementation topic that turns the mathematical definition n! = n * (n-1)! with 1! = 1 into a recursive function, showing how the definition supplies both the base case and the recursive case; learners code and trace factorial as their first recursive routine.

  • A guided example implementing fibonacci(n) in JavaScript, where the recursive case makes two recursive calls instead of one, including choosing the base case values for 0 and 1 and observing the repeated work this branching creates; learners use it to see the cost of naive recursion.

  • A topic on processing arrays and linked lists recursively by handling the first element and passing the remainder to the same function, presented as an alternative to index-based loops; learners apply it to write traversal, sum, and search routines over list structures.

  • A decision-focused reading comparing recursion against iteration on criteria such as how well each maps to the problem's structure, readability, and performance or memory cost, helping learners judge when recursion is the right design choice rather than just a possible one.

  • A consolidated module overview that stitches together all seven topics — definition of recursion, base and recursive cases, the call stack, factorial, Fibonacci, list traversal, and recursion versus iteration — into a single continuous document for review or printing before an assessment.

Readings (1)

Reading for this module: drafted with AI from the module's topics, or brought in from the course's own files.

  • Examines the trade-offs between recursion and iterative loops, guiding learners and instructors in identifying problem types — such as tree traversal and divide-and-conquer — where recursion is most appropriate versus where iteration is preferred.