Lab 11: Knowledge Check
These questions check your knowledge of concepts from this lab. Use the button at the bottom to show your answers once you've attempted them.
-
The base case of a recursive function must return without making any recursive function calls.
True False -
In the case-by-case method of recursive problem solving, before writing your final recursive case and simplifying your solution, the intermediate recursive cases are less complicated than standard recursion because their recursive function calls... (pick one or more)
- ...use 'small' values which are not as complicated.
- ...do not use variables as arguments.
- ...are guaranteed to enter a case which has already been written.
- ...are all calls into the base case.
-
Which of the following correctly describe(s) the relationships between function call frames in a recursive function? (pick one or more)
- The first function call frame to be created is also the first function call frame to be destroyed.
- The last function call frame to be created is also the last function call frame to be destroyed.
- The first function call frame to be created is the last function call frame to be destroyed.
- Base case function call frames are the only frames which do not create more function call frames of the recursive function.
- All recursive function call frames created by another frame will themselves end before the frame that created them does.
- Although the recursive calls determine the order in which function call frames are created, the position of return statements determines the order in which they are destroyed.
-
If we run the following code, how many recursive and base-case function call frames will be generated in total?
def branch(x): if x <= 0: return else: print('-' * x) branch(x-1) branch(x//2) branch(2)
- 1 recursive frame, 2 base-case frames
- 2 recursive frames, 2 base-case frames
- 2 recursive frames, 4 base-case frames
- 3 recursive frames, 4 base-case frames
- 3 recursive frames, 6 base-case frames
Table of Contents
- Lab 11 Home
- Part 1: Exercises (start with B notebook)
- Part 2A: Recursive Turtles (work on this part OR the next one)
- Part 2B: Recursive Drums (work on this part OR the previous one)
- Reference: Case-by-case recursion strategy
- Reference: Recursive design patterns
- Knowledge Check