# Data Structure Questions and Answers-Factorial using Recursion

## Click on any option to know the CORRECT ANSWERS

 Question 1
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
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
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
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
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)