NEW
Font size
WorksheetsDSA (QUIZ 3) - Recursion
Total questions: 15
Worksheet time: 15mins
What is the main difference between recursion and iteration in programming?
Recursion involves loops, while iteration involves function calls.
Recursion involves function calls, while iteration involves loops.
Recursion and iteration are the same.
Recursion is faster than iteration.
Which of the following problems is best suited for a recursive solution?
Summing an array of integers
Printing 'Hello, World!' 10 times
Calculating the factorial of a number
Finding the maximum value in a list
What is the base case in the recursive definition of the Fibonacci sequence?
F(n)=F(n−1)+F(n−2)F(n) = F(n-1) + F(n-2)
F(n)=nF(n) = n
F(0)=0F(0) = 0 and F(1)=1F(1) = 1
F(n)=2F(n−1)F(n) = 2F(n-1)
In the Tower of Hanoi problem, what is the minimum number of moves required to solve the puzzle with 5 disks?
15
31
63
127
Which of the following is a correct recursive function to calculate the factorial of a number n?
def factorial(n): return n * factorial(n+1)
def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)
def factorial(n): return n + factorial(n-1)
def factorial(n): return n * factorial(n-2)
What is the time complexity of calculating the nth Fibonacci number using simple recursion?
O(n)
O(log n)
O(n^2)
O(2^n)
Which of the following statements about recursion is false?
Recursive functions always have a base case.
Recursion can lead to stack overflow if not implemented correctly.
Recursion always results in more efficient algorithms than iteration.
Recursion can be used to solve problems that can be broken down into smaller subproblems.
What is the value of F(10) in the Fibonacci sequence?
21
34
55
89
In the Tower of Hanoi puzzle, what are the three rods typically called?
A, B, C
Source, Auxiliary, Target
Left, Middle, Right
Start, Helper, End
What is the purpose of the base case in a recursive function?
To ensure the function runs indefinitely.
To prevent infinite recursion by providing a stopping condition.
To increase the complexity of the function.
To minimize the function's execution time.
Which of the following is a real-world application of the Tower of Hanoi algorithm?
Sorting a list of numbers
Managing incremental backups
Generating random numbers
Encrypting data
What is the value of 4! (4 factorial)?
4
12
24
120
Which of the following functions can be used to traverse a binary tree recursively?
Pre-order traversal
In-order traversal
Post-order traversal
All of the above
Why is it important to have a base case in a recursive algorithm?
To ensure the algorithm is efficient
To provide a stopping point for the recursion
To make the algorithm more complex
To optimize memory usage
How many moves are required to solve the Tower of Hanoi puzzle with 6 disks?
31
63
127
255
