# YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

## 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; }

10 | |

1 | |

10 9 8 ... 1 0 | |

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; }

return | |

printf("%d ", n) | |

if(n == 0) | |

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; }

9 | |

10 | |

11 | |

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; }

Prints the numbers from 10 to 1 | |

Prints the numbers from 10 to 0 | |

Prints the numbers from 1 to 10 | |

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?

Recursion is always better than iteration | |

Recursion uses more memory compared to iteration | |

Recursion uses less memory compared to iteration | |

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.