PDF Download
FREE AND STUDY GAMES ABOUT RECURSION EXAM
QUESTIONS
Actual Qs and Ans Expert-Verified Explanation
This Exam contains:
-Guarantee passing score -8 Questions and Answers -format set of multiple-choice -Expert-Verified Explanation
Question 1: What are the 2 parts of a recursive function?
Answer:
Recursive functions consist of a base case and recursive case. Recursive case is when the function calls itself. Base case is when the function stops calling itself so it doesn't go into an infinite loop.
Question 2: What's a good analogy for a stack?
Answer:
A pile of post-it notes. You can only add notes to the top of the stack, and the last one added must be the first removed.
Question 3: What is a stack?
Answer:
A simple data structure w/ a predefined capacity. It allows adding and removing objects in a particular order. Items can only be added to the top of the stack, and the only element that can be removed is the element at the top of the stack
Question 4: Describe the call stack
Answer:
When a function is called, a certain amount of memory is set aside for that function to use for purposes such as storing local variables. It is also used by the computer to store info about the function, like the function's address in memory.Question 5: Why do recursive functions have the tendency to use a lot of memory?
Answer:
Keeping track of the information about active functions and their variables can use up a lot of memory if the recursion goes many levels deep. If you have a lot of function calls, your program will run significantly slower.
Question 6: What are the 2 operations for a stack?
Answer:
push and pop Question 7: How is recursion different from a loop? Which is better for performance?
Answer:
It can accomplish the same thing as a loop, but it makes the solution clearer There is no performance benefit to using recursion (loops may in fact be better), but it can make the program easier to read.
Question 8: What is recursion?
Answer:
Recursion is where a function calls itself