

MCQOPTIONS
Saved Bookmarks
This section includes 10 Mcqs, each offering curated multiple-choice questions to sharpen your Data Structures and Algorithms knowledge and support exam preparation. Choose a topic below to get started.
1. |
How many times will the function fact() be called when the following code is executed? |
A. | 4 |
B. | 5 |
C. | 6 |
D. | 7View Answer |
Answer» D. 7View Answer | |
2. |
Consider the following recursive implementation to find the factorial of a number. Which of the lines is the base case? |
A. | return 1 |
B. | return n * fact(n-1) |
C. | if(n == 0) |
D. | if(n == 1)View Answer |
Answer» D. if(n == 1)View Answer | |
3. |
What is the space complexity of the following recursive implementation to find the factorial of a number? |
A. | O(1) |
B. | O(n) |
C. | O(n2) |
D. | O(n3)View Answer |
Answer» B. O(n) | |
4. |
The time complexity of the following recursive implementation to find the factorial of a number is ________ |
A. | O(1) |
B. | O(n) |
C. | O(n2) |
D. | O(n3)View Answer |
Answer» C. O(n2) | |
5. |
Consider the following recursive implementation to find the factorial of a number. Which of the lines should be inserted to complete the below code? |
A. | n = 0 |
B. | n != 0 |
C. | n == 0 |
D. | n == 1View Answer |
Answer» D. n == 1View Answer | |
6. |
Consider the following iterative implementation to find the factorial of a number. Which of the lines should be inserted to complete the below code? |
A. | fact = fact + i |
B. | fact = fact * i |
C. | i = i * fact |
D. | i = i + factView Answer |
Answer» C. i = i * fact | |
7. |
In general, which of the following methods isn’t used to find the factorial of a number? |
A. | Recursion |
B. | Iteration |
C. | Dynamic programming |
D. | Non iterative / recursive |
Answer» E. | |
8. |
What is the time complexity of the above recursive implementation to find the factorial of a number? |
A. | O(1) |
B. | O(n) |
C. | O(n<sup>2</sup>) |
D. | O(n<sup>3</sup>) |
Answer» D. O(n<sup>3</sup>) | |
9. |
Which of the following recursive formula can be used to find the factorial of a number? |
A. | fact(n) = n * fact(n) |
B. | fact(n) = n * fact(n+1) |
C. | fact(n) = n * fact(n-1) |
D. | fact(n) = n * fact(1) |
Answer» D. fact(n) = n * fact(1) | |
10. |
Which of the following methods can be used to find the factorial of a number? |
A. | Recursion |
B. | Iteration |
C. | Dynamic programming |
D. | All of the mentioned |
Answer» E. | |