Data Structure Questions and Answers-Factorial using Recursion

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Factorial using Recursion

Congratulations - you have completed Data Structure Questions and Answers-Factorial using Recursion.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%


Your answers are highlighted below.
Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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
Question 1 Explanation: 
All of the above mentioned methods can be used to find the factorial of a number.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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)
Question 2 Explanation: 
fact(n) = n * fact(n - 1) can be used to find the factorial of a number.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Consider the following iterative implementation to find the factorial of a number:

int main() { int n = 6,  i; int fact = 1; for(i=1;i<=n;i++) .....; printf("%d", fact); return 0; }

Which of the following lines should be inserted to complete the above code?

A
fact = fact + i
B
fact = fact * i
C
i = i * fact
D
i = i + fact
Question 3 Explanation: 
The line "fact = fact * i" should be inserted to complete the above code.

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Consider the following recursive implementation to find the factorial of a number:

int fact(int n) { if(.....) return 1; return n * fact(n - 1); } int main() { int n = 5; int ans = fact(n); printf("%d", ans); return 0; }

Which of the following lines should be inserted to complete the above code?

A
n = 0
B
n != 0
C
n == 0
D
n == 1
Question 4 Explanation: 
The line "n == 0" should be inserted to complete the above code.

Note: "n == 1" cannot be used because it does not take care of the case when n = 0, i.e when we want to find the factorial of 0.

Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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(n2)
D
O(n3)
Question 5 Explanation: 
The time complexity of the above recursive implementation to find the factorial of a number is O(n).

Once you are finished, click the button below. Any items you have not completed will be marked incorrect. Get Results
There are 5 questions to complete.

DOWNLOAD FREE PDF <<CLICK HERE>>