Day 11 & Day 12 – Recursion and Advanced Functions (Python Quiz)

Day 11 – Recursion

  • Recursion is a function calling itself
  • Every recursion must have:
    • Base Case – stops recursion
    • Recursive Case – function calls itself
  • Without base case → infinite recursion → error
  • Recursion uses call stack (extra memory)
  • Used in factorial, Fibonacci, tree & graph problems
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

Day 12 – Advanced Functions & DSA Thinking

  • Functions can return multiple values (tuple)
  • Functions can be passed as arguments
  • DSA problems require breaking problem into smaller parts
  • Interview focus: explanation of base case + logic
def calc(a, b):
    return a+b, a-b
1. What is recursion in Python?
Recursion is when a function calls itself to solve smaller sub-problems.
2. What is the purpose of a base case in recursion?
Base case stops further recursive calls.
3. What happens if a recursive function has no base case?
Without a base case, recursion never stops and causes an error.
4. Which data structure manages recursive function calls?
Each recursive call is stored in the call stack.
5. Which problem is naturally suited for recursion?
Tree and divide-and-conquer problems suit recursion.
6. What does a recursive function usually do?
Recursion reduces the problem size in each call.
7. Which statement about recursion is true?
Recursive calls use stack memory.
8. What does a function return if there is no return statement?
Python returns None by default.
9. Multiple values returned from a function are stored as?
Python packs multiple return values into a tuple.
10. What is the correct base case for factorial?
Factorial of 1 is 1.
11. Functions passed as arguments indicate?
Python treats functions as first-class objects.
12. Which is NOT a benefit of recursion?
Recursion uses more memory due to stack calls.
13. Which problem requires recursion instead of loop?
Tree traversal is naturally recursive.
14. What is the main focus of interviewers in recursion questions?
Interviewers want to see how you think.
15. Which statement about functions is correct?
Functions help reuse and organize code.
Your Score: 0 / 15

Post a Comment

0 Comments