Lab 12: 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.
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 12 Home
- Part 0: Non-fruitful recursion Warm up
- Part 1: Non-fruitful Recursive Characters
- Part 2: Fruitful Recursion I
- Part 3: Fruitful Recursion II
- Reference: Recursive Design Patterns
- Knowledge Check