What is the main problem with using plain recursion for some problems?
Plain recursion can repeat the same calculations many times, which wastes time and makes the program slow.
Click to reveal answer
beginner
What does Dynamic Programming (DP) do to improve recursion?
DP saves the results of subproblems so they don’t have to be calculated again, making the program faster.
Click to reveal answer
intermediate
What is 'overlapping subproblems' in the context of recursion?
It means the same smaller problems are solved multiple times during recursion.
Click to reveal answer
beginner
Why is recursion alone not efficient for problems like Fibonacci numbers?
Because it recalculates the same Fibonacci numbers many times, causing exponential time complexity.
Click to reveal answer
beginner
How does memoization help in recursion?
Memoization stores answers to subproblems in a table so that when the same problem appears again, the answer is reused instead of recalculated.
Click to reveal answer
What is the main reason to use Dynamic Programming instead of plain recursion?
ATo avoid repeating calculations of the same subproblems
BTo make the code shorter
CTo use more memory without speed benefit
DTo avoid using loops
✗ Incorrect
Dynamic Programming avoids repeating calculations by saving results of subproblems.
Which problem characteristic suggests that Dynamic Programming can help?
AOnly one big problem with no smaller parts
BNo repeated subproblems
COverlapping subproblems
DProblems that do not use recursion
✗ Incorrect
Overlapping subproblems mean the same smaller problems appear multiple times, which DP can optimize.
What is memoization in Dynamic Programming?
ASaving results of subproblems to reuse later
BWriting code without recursion
CUsing loops instead of recursion
DIgnoring subproblems
✗ Incorrect
Memoization stores answers to subproblems to avoid recalculating them.
Why does plain recursion for Fibonacci numbers become slow?
AIt uses too much memory
BIt only calculates the first number
CIt does not use recursion properly
DIt recalculates the same Fibonacci numbers many times
✗ Incorrect
Plain recursion repeats calculations for the same Fibonacci numbers, causing slow performance.
Which of these is NOT a benefit of Dynamic Programming?
AUsing extra memory to store results
BAlways using less memory than recursion
CSimplifying problems by breaking them into subproblems
DFaster execution by avoiding repeated work
✗ Incorrect
Dynamic Programming often uses more memory to store results, so it does not always use less memory than recursion.
Explain why recursion alone can be inefficient and how Dynamic Programming fixes this problem.
Think about how many times the same small problem is solved.
You got /4 concepts.
Describe the concept of overlapping subproblems and why it matters for choosing Dynamic Programming.
Focus on repeated work in recursion.
You got /4 concepts.
Practice
(1/5)
1. Why do we use dynamic programming instead of plain recursion for some problems?
easy
A. Because dynamic programming uses less memory than recursion
B. Because dynamic programming stores results to avoid repeated work
C. Because recursion cannot solve problems with multiple choices
D. Because recursion is always slower than loops
Solution
Step 1: Understand recursion's limitation
Recursion often recalculates the same subproblems multiple times, causing inefficiency.
Step 2: Role of dynamic programming
Dynamic programming saves results of subproblems (memoization) to avoid repeated calculations.
Final Answer:
Because dynamic programming stores results to avoid repeated work -> Option B
Quick Check:
Memoization avoids repeated work = D [OK]
Hint: Dynamic programming saves repeated results to speed up recursion [OK]
Common Mistakes:
Thinking recursion is always slower than loops
Believing recursion can't handle multiple choices
Confusing memory use between recursion and DP
2. Which Go syntax correctly declares a recursive function to compute Fibonacci numbers?
easy
A. func fib(n int) int { if n <= 1 { return n } return fib(n-1) + fib(n-2) }
B. func fib(n int) { if n <= 1 { return n } return fib(n-1) + fib(n-2) }
C. func fib(n int) int { if n < 0 { return 0 } return fib(n-1) + fib(n-2) }
D. func fib(n int) int { if n == 0 { return 0 } else { return fib(n-1) + fib(n-2) } }
Solution
Step 1: Check function signature and return type
func fib(n int) int { if n <= 1 { return n } return fib(n-1) + fib(n-2) } correctly declares return type int and returns int values.
Step 2: Verify base cases and recursion
func fib(n int) int { if n <= 1 { return n } return fib(n-1) + fib(n-2) } uses base case n <= 1 returning n, and recursive calls fib(n-1)+fib(n-2), which is correct.
Final Answer:
func fib(n int) int { if n <= 1 { return n } return fib(n-1) + fib(n-2) } -> Option A
Quick Check:
Correct signature and base case = B [OK]
Hint: Check function return type and base cases carefully [OK]
Common Mistakes:
Missing return type in function signature
Incorrect base case conditions
Returning void instead of int
3. What is the output of this Go code snippet?
import "fmt"
func fib(n int) int {
if n <= 1 {
return n
}
return fib(n-1) + fib(n-2)
}
func main() {
fmt.Println(fib(5))
}