Page 1
Wink Notes
B.Tech CSE — 4th Semester
Design and Analysis of Algorithms
— Unit - 4 —
1. The Flaw of Standard Recursion
Divide and Conquer solves problems by splitting them into completely independent subproblems. But what happens if the subproblems are NOT independent? What if the recursion tree forces you to solve the exact same mathematical problem hundreds of times?
1.1 The Fibonacci Disaster
Consider the naive recursive function for the Fibonacci sequence: `fib(n) = fib(n-1) + fib(n-2)`.
If you call `fib(5)`, it calls `fib(4)` and `fib(3)`.
The `fib(4)` call then recursively calls `fib(3)` again.
The execution tree grows exponentially. To calculate `fib(50)`, the CPU will literally compute the answer to `fib(2)` over a trillion times. The time complexity is .
Dynamic Programming (DP) is a paradigm designed specifically to cure this exact disease.