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.

  1. The base case of a recursive function must return without making any recursive function calls.
    True False
  2. 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)
    1. ...use 'small' values which are not as complicated.
    2. ...do not use variables as arguments.
    3. ...are guaranteed to enter a case which has already been written.
    4. ...are all calls into the base case.
  3. Which of the following correctly describe(s) the relationships between function call frames in a recursive function? (pick one or more)
    1. The first function call frame to be created is also the first function call frame to be destroyed.
    2. The last function call frame to be created is also the last function call frame to be destroyed.
    3. The first function call frame to be created is the last function call frame to be destroyed.
    4. Base case function call frames are the only frames which do not create more function call frames of the recursive function.
    5. All recursive function call frames created by another frame will themselves end before the frame that created them does.
    6. 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.
  4. 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. 1 recursive frame, 2 base-case frames
    2. 2 recursive frames, 2 base-case frames
    3. 2 recursive frames, 4 base-case frames
    4. 3 recursive frames, 4 base-case frames
    5. 3 recursive frames, 6 base-case frames

Table of Contents