CS21: Quiz 6 Study Guide

In addition to all concepts from Quiz 1, Quiz 2, Quiz 3, Quiz 4, and Quiz 5

You should understand the following terms and concepts:

You should be able to do the following:

Practice problems:

  1. How many steps are required for each of the following?

  2. Consider the following function, oneLoop(L), which is similar to the inner loop from bubble sort:

    Write an expression for the asymptotic runtime of oneLoop, in terms of the length n of the list L.

  3. Show how the following list would be changed after selection sort does its first 3 swaps:

  4. Show how the following list would be changed after bubble sort does one iteration of the outer loop.

  5. Which algorithm requires time directly proportional to the size of the input list?

  6. Write a recursive function longestInList(L) that returns the longest string in L, a list of strings.

    Then, draw the stack as it would look at its largest (i.e, the deepest part of the recursion when it hits a base case), when the function is called on the list ['awesome', 'recursive', 'code']. pdf of solution

  7. Write a recursive function countdown(n) which simulates a countdown to a rocket launch. If you call blastoff(4) you should see the following output:

    This function is only called for its side-effects (printing), and not its return value.

  8. Write a recursive function recBinary(x,L) which implements a recursive version of binary search for item x in list L. It should return True if x is in L, and False otherwise.

  9. For additional recursive function problems, try problems on this page.