Q1: Base Case
What is the primary purpose of a base case in a recursive function?
- To improve the function's performance significantly.
- To define the initial input values.
- To prevent the function from calling itself indefinitely, stopping the recursion.
- To handle any potential errors that may arise.
Q2: Tail Recursion
Which of the following best describes a tail-recursive function?
- A function that calls itself multiple times within a single iteration.
- A function where the recursive call is the very last operation performed in the function.
- A function that does not require a base case.
- A function that is optimized for handling strings.
Q3: Stack Overflow
What is a common cause of a 'stack overflow' error when using recursion?
- Insufficient memory allocated to the heap.
- Reaching the maximum integer value.
- Exceeding the maximum recursion depth allowed by the system.
- Using incorrect data types.
Q4: Factorial Recursion
What is the time complexity of a recursive function to calculate the factorial of a number 'n'?
- O(log n)
- O(n)
- O(n^2)
- O(2^n)
Q5: Fibonacci
Why is the straightforward recursive implementation of the Fibonacci sequence inefficient?
- Because it uses iterative methods.
- Because it recalculates the same Fibonacci numbers multiple times.
- Because it cannot be implemented using recursion.
- Because it requires very large stack memory.
Q6: Memoization
What is memoization, and how does it improve the performance of recursive functions?
- A technique to increase the size of the stack.
- A technique for storing the results of expensive function calls and returning the cached result when the same inputs occur again.
- A technique to reduce the number of variables used in the function.
- A technique that forces the function to run in parallel.
Q7: Permutations
Which algorithm is most suitable for generating all permutations of a given string?
- Depth-first search (DFS) using recursion.
- Breadth-first search (BFS) using a queue.
- Dynamic programming.
- Greedy Algorithm
Q8: Subset Generation
What programming technique is commonly used to find all possible subsets of a set?
- Iterative looping.
- Recursion with backtracking.
- Using a hash table.
- Linear Search
Q9: Backtracking
What is the core concept behind backtracking algorithms?
- Exploring the solution space by iteratively improving the current best solution.
- Exploring the solution space incrementally, abandoning paths when they don't lead to a solution.
- Dividing the problem into smaller subproblems and solving them independently.
- Randomly exploring the solution space to find a near-optimal solution.
Q10: N-Queens
Which of the following problems can be effectively solved using a backtracking algorithm?
- Sorting a list of numbers.
- Finding the shortest path in a graph.
- The N-Queens problem.
- Calculating the area of a circle.
Q11: Sudoku Solver
In a recursive Sudoku solver, what typically represents the base case?
- Finding an empty cell to fill.
- Filling a row or column.
- The Sudoku grid is fully filled and valid.
- The Sudoku grid is invalid.
Q12: Tree Traversal
Which tree traversal algorithm is naturally implemented using recursion?
- Breadth-first search (BFS).
- Depth-first search (DFS).
- Dijkstra's Algorithm.
- Binary Search
Q13: Optimizing Recursion
Besides memoization, what's another common technique to optimize recursive functions, particularly tail-recursive ones?
- Using a global variable.
- Tail call optimization.
- Increasing the stack size.
- Using a different programming language.
Q14: Space Complexity
What is the space complexity associated with a non-tail-recursive function?
- O(1) constant space.
- O(log n) logarithmic space.
- O(n) linear space, due to the call stack.
- O(n^2) quadratic space.
Q15: Recursive Case
In a recursive function, what does the 'recursive case' primarily do?
- Defines the stopping condition.
- Calls the function itself with modified arguments, working towards the base case.
- Returns a constant value.
- Handles any errors encountered.