wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

DSA (QUIZ 3) - Recursion

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.

What is the main difference between recursion and iteration in programming?

a)

Recursion involves loops, while iteration involves function calls.

b)

Recursion involves function calls, while iteration involves loops.

c)

Recursion and iteration are the same.

d)

Recursion is faster than iteration.

2.

Which of the following problems is best suited for a recursive solution?

a)

Summing an array of integers

b)

Printing 'Hello, World!' 10 times

c)

Calculating the factorial of a number

d)

Finding the maximum value in a list

3.

What is the base case in the recursive definition of the Fibonacci sequence?

a)

F(n)=F(n−1)+F(n−2)F(n) = F(n-1) + F(n-2)

b)

F(n)=nF(n) = n

c)

F(0)=0F(0) = 0 and F(1)=1F(1) = 1

d)

F(n)=2F(n−1)F(n) = 2F(n-1)

4.

In the Tower of Hanoi problem, what is the minimum number of moves required to solve the puzzle with 5 disks?

a)

15

b)

31

c)

63

d)

127

5.

Which of the following is a correct recursive function to calculate the factorial of a number n?

a)

def factorial(n): return n * factorial(n+1)

b)

def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)

c)

def factorial(n): return n + factorial(n-1)

d)

def factorial(n): return n * factorial(n-2)

6.

What is the time complexity of calculating the nth Fibonacci number using simple recursion?

a)

O(n)

b)

O(log n)

c)

O(n^2)

d)

O(2^n)

7.

Which of the following statements about recursion is false?

a)

Recursive functions always have a base case.

b)

Recursion can lead to stack overflow if not implemented correctly.

c)

Recursion always results in more efficient algorithms than iteration.

d)

Recursion can be used to solve problems that can be broken down into smaller subproblems.

8.

What is the value of F(10) in the Fibonacci sequence?

a)

21

b)

34

c)

55

d)

89

9.

In the Tower of Hanoi puzzle, what are the three rods typically called?

a)

A, B, C

b)

Source, Auxiliary, Target

c)

Left, Middle, Right

d)

Start, Helper, End

10.

What is the purpose of the base case in a recursive function?

a)

To ensure the function runs indefinitely.

b)

To prevent infinite recursion by providing a stopping condition.

c)

To increase the complexity of the function.

d)

To minimize the function's execution time.

11.

Which of the following is a real-world application of the Tower of Hanoi algorithm?

a)

Sorting a list of numbers

b)

Managing incremental backups

c)

Generating random numbers

d)

Encrypting data

12.

What is the value of 4! (4 factorial)?

a)

4

b)

12

c)

24

d)

120

13.

Which of the following functions can be used to traverse a binary tree recursively?

a)

Pre-order traversal

b)

In-order traversal

c)

Post-order traversal

d)

All of the above

14.

Why is it important to have a base case in a recursive algorithm?

a)

To ensure the algorithm is efficient

b)

To provide a stopping point for the recursion

c)

To make the algorithm more complex

d)

To optimize memory usage

15.

How many moves are required to solve the Tower of Hanoi puzzle with 6 disks?

a)

31

b)

63

c)

127

d)

255