Data Structure Questions and Answers-Recursion

YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

CLICK HERE TO DOWNLOAD

Data Structure Questions and Answers-Recursion

Question 6 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the output of the following code?

void my....recursive....function(int n) { if(n == 0) return; printf("%d ", n); my....recursive....function(n-1); } int main() { my....recursive....function(10); return 0; }
A
10
B
1
C
10 9 8 ... 1 0
D
10 9 8 ... 1
Question 6 Explanation: 
The program prints the numbers from 10 to 1.

Question 7 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the base case for the following code?

void my....recursive....function(int n) { if(n == 0) return; printf("%d ", n); my....recursive....function(n-1); } int main() { my....recursive....function(10); return 0; }
A
return
B
printf("%d ", n)
C
if(n == 0)
D
my....recursive....function(n-1)
Question 7 Explanation: 
For the base case, the recursive function is not called. So, "if(n == 0)" is the base case.

Question 8 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How many times is the recursive function called, when the following code is executed?

void my....recursive....function(int n) { if(n == 0) return; printf("%d ", n); my....recursive....function(n-1); } int main() { my....recursive....function(10); return 0; }
A
9
B
10
C
11
D
12
Question 8 Explanation: 
The recursive function is called 11 times.

Question 9 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What does the following recursive code do?

void my....recursive....function(int n) { if(n == 0) return; my....recursive....function(n-1); printf("%d ", n); } int main() { my....recursive....function(10); return 0; }
A
Prints the numbers from 10 to 1
B
Prints the numbers from 10 to 0
C
Prints the numbers from 1 to 10
D
Prints the numbers from 0 to 10
Question 9 Explanation: 
The above code prints the numbers from 1 to 10.

Question 10 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which of the following statements is true?
A
Recursion is always better than iteration
B
Recursion uses more memory compared to iteration
C
Recursion uses less memory compared to iteration
D
Iteration is always better and simpler than recursion
Question 10 Explanation: 
Recursion uses more memory compared to iteration because every time the recursive function is called, the function call is stored in stack.

There are 10 questions to complete.