Recursion is when a function calls itself to solve smaller parts of a problem until it reaches a simple case it can solve directly.
Click to reveal answer
beginner
Why do we need recursion when we have loops?
Loops repeat actions but cannot easily handle problems that break down into smaller similar problems, like tree traversals or factorial calculations. Recursion naturally fits these cases.
Click to reveal answer
intermediate
Give an example of a problem that loops cannot express cleanly but recursion can.
Calculating factorial of a number or traversing a folder structure (tree) is easier and cleaner with recursion than with loops.
Click to reveal answer
beginner
What is a base case in recursion?
A base case is the simplest situation in recursion that can be solved directly without further recursive calls. It stops the recursion from continuing forever.
Click to reveal answer
intermediate
How does recursion help in expressing divide-and-conquer algorithms?
Recursion breaks a big problem into smaller similar problems, solves each smaller problem, and combines the results. This matches divide-and-conquer naturally.
Click to reveal answer
Which of these problems is best solved using recursion?
ACalculating the sum of numbers from 1 to n
BPrinting numbers from 1 to 10
CFinding the factorial of a number
DAdding two numbers
✗ Incorrect
Factorial calculation naturally breaks down into smaller factorial problems, making recursion a clean solution.
What stops a recursive function from running forever?
ABase case condition
BLoop inside the function
CCalling another function
DUsing variables
✗ Incorrect
The base case tells the function when to stop calling itself.
Which structure is often easier to traverse using recursion than loops?
ALinked list
BTree
CArray
DQueue
✗ Incorrect
Trees have branches and sub-branches that recursion can handle naturally.
Loops are less suitable than recursion for problems that:
ARepeat a fixed number of times
BPrint text
CAdd numbers
DBreak down into smaller similar problems
✗ Incorrect
Recursion handles problems that divide into smaller similar parts better than loops.
What is a key difference between loops and recursion?
ARecursion can express self-similar problems naturally
BLoops use less memory than recursion
CLoops are slower than recursion
DRecursion cannot repeat actions
✗ Incorrect
Recursion naturally fits problems where the solution involves solving smaller versions of the same problem.
Explain why recursion is useful for problems that loops cannot express cleanly.
Think about how a problem can be divided into smaller similar problems.
You got /5 concepts.
Describe the role of the base case in recursion and what happens if it is missing.
What stops the function from calling itself endlessly?
You got /5 concepts.
Practice
(1/5)
1. Why do we use recursion instead of loops in some problems?
easy
A. Because loops cannot repeat tasks
B. Because loops are slower than recursion in all cases
C. Because recursion uses less memory than loops
D. Because recursion can express problems with self-similar structure more clearly
Solution
Step 1: Understand problem structure
Some problems have parts that look like smaller versions of themselves, like a tree or factorial calculation.
Step 2: Compare recursion and loops
Loops repeat tasks but cannot naturally express self-similar or nested structures clearly, while recursion can call itself to handle these.
Final Answer:
Because recursion can express problems with self-similar structure more clearly -> Option D
Quick Check:
Recursion = self-similar clarity [OK]
Hint: Recursion fits problems with repeated smaller versions [OK]
Common Mistakes:
Thinking loops are always faster
Believing recursion always uses less memory
Assuming loops cannot repeat tasks
2. Which of the following is the correct syntax to define a recursive method in C#?
easy
A. void RecursiveMethod() { RecursiveMethod(); }
B. void RecursiveMethod() { while(true) { RecursiveMethod(); } }
C. void RecursiveMethod() { if(condition) RecursiveMethod(); else return; }
D. void RecursiveMethod() { for(int i=0; i<10; i++) RecursiveMethod(); }
Solution
Step 1: Identify base case in recursion
Recursive methods must have a condition to stop calling themselves to avoid infinite loops.
Step 2: Check options for base case
Only void RecursiveMethod() { if(condition) RecursiveMethod(); else return; } has a condition that stops recursion with an else return statement.