Fibonacci Sequence Using Recursion

Introduction

The Fibonacci sequence is defined by a simple rule: each number is the sum of the two before it, starting from 0 and 1. That definition is itself recursive, which makes Fibonacci the classic example of a function whose recursive case contains two recursive calls instead of one. In this topic you will write fibonacci(n) in JavaScript, decide which values must be handled as base cases (typically n equal to 0 and n equal to 1), and confirm that every path through the function eventually reaches one of them.

What makes Fibonacci more interesting than factorial is what happens to the call stack. Because each call spawns two more calls, the execution forms a branching tree rather than a single chain, and the same subproblems get recomputed over and over. Tracing fibonacci(4) or fibonacci(5) by hand on paper is the fastest way to see this: you will notice fib(2) appearing several times in the tree. That redundancy is why the naive version grows roughly exponentially in running time, even though it is only a few lines of code.

The videos below approach Fibonacci from the dynamic programming side, which is exactly where this conversation leads. As you watch, pay attention to how the presenter describes the repeated subproblems in the recursion tree, how memoization (the top-down approach) stores results so each value is computed only once, and how the bottom-up approach replaces recursion with a loop entirely. The code shown is not JavaScript, but the recursive structure, base cases and stack behavior translate directly; focus on the logic and then re-express it in JavaScript yourself.

Video 1: Top Down Approach - Fibonacci Number in Dynamic Programming | Implementation

Dinesh Varyani · 9:40 · 4,468 views · 5y ago · captions — Watch on YouTube

About this video

This video walks through implementing the top-down (memoized) approach to computing Fibonacci numbers. It starts from the recursive definition with its base cases and shows how adding a cache for already-computed values changes the recursion from exponential to linear work. Expect a line-by-line implementation walkthrough rather than pure theory.

Why this video

It directly addresses the performance trade-off subtopic by showing what the naive recursion wastes and how memoization fixes it, while keeping the recursive structure and base cases visible.

Video 2: Bottom Up Approach - Fibonacci Number in Dynamic Programming | Animation

Dinesh Varyani · 13:04 · 6,722 views · 5y ago · captions — Watch on YouTube

About this video

An animated explanation of the bottom-up approach to Fibonacci, building the sequence from the smallest values upward instead of recursing downward. The animation is intended to make the order of computation and the reuse of previously computed values easy to follow visually.

Why this video

The animation gives you a concrete picture of which subproblems get computed and in what order, which is useful context for comparing recursion against iteration and for judging when recursion is the better choice.

Video 3: Bottom Up Approach - Fibonacci Number in Dynamic Programming | Implementation

Dinesh Varyani · 7:34 · 4,400 views · 5y ago · captions — Watch on YouTube

About this video

This is the coding counterpart to the bottom-up animation, implementing the iterative Fibonacci solution step by step. It should show how the loop replaces the recursive calls and how only a small amount of stored state is needed.

Why this video

Seeing the iterative version implemented right after the recursive one makes the readability-versus-performance comparison concrete and shows one practical way to avoid deep call stacks entirely.

How These Videos Support the Learning Outcomes

Together these videos reinforce the module outcomes around Fibonacci. All three begin from the recursive definition and its base cases, supporting your ability to separate base case from recursive case (MO1) and to write the function yourself in JavaScript (MO2). The discussion of repeated subproblems in the recursion tree directly supports tracing how the call stack branches and resolves for a small input such as fibonacci(4) (MO3). The contrast between the top-down memoized version and the bottom-up iterative version gives you the evidence needed to argue when recursion is appropriate and when iteration is preferable (MO4), and the explicit treatment of redundant recalculation plus the stack-free loop addresses the performance trade-offs and stack overflow mitigation strategies (MO5).

About These Videos

These videos were chosen from YouTube on October 2, 2026. Each has captions; the player turns them on. Videos on YouTube can be changed or removed — if one no longer plays, tell your instructor. If a player does not appear, use its Watch on YouTube link.