COP 4531 Practice Midterm Exam Fall 2007

  1. Heap Algorithms. Begin with the vector v = [ xx , xx , xx , xx , xx , xx ].
    1. Show the vector after v.PushBack(xx). (5 pts)
    2. Show the vector after fsu::g_push_heap(v.Begin(), v.End()). (Show work.) (5 pts)
  2. Among the possible answers in the table below, what best describes the worst case runtime of the following algorithms? (10 algorithms, 2 pts each)
    Possible Answers
    1. O(1)
    2. Amortized O(1)
    3. O(log depth)
    4. O(depth)
    5. O(log size)
    6. O(size)
    7. O(size x log size)
    8. O(size2)
    9. None of the above
  3. Set Clients
    1. Declare three CSet<> objects with elements of type String: one named myStrings to hold words in a text, one named good to hold known correctly spelled words, and one named myBad to report mispelled words from the text. Use default order to structure the sets. Ignore namespaces. (5 pts)
    2. Write a program fragment that reads strings from a file named myText into myStrings and strings from myDictionary into myGood and computes myBad. Use generic algorithms or set operations to make the computation. You may assume that the two input files are ``nothing but strings'' to make reading simple. It is not necessary to check for file opening errors. (5 pts)
  4. Sorts Theory (5 pts each)
    1. What is a comparison sort?
    2. What is the theoretical lower bound on the asymptotic worst case runtime for a comparison sort?
    3. Give a short explanation of this fact.
  5. Comparison Sort (2 pts each)
    1. Name one comparison sort whose asymptotic worst case run time is at the theoretical limit described above:
    2. What assumptions does this sort place on iterators defining the range to be sorted?
    3. What is the asymptotic run space requirement of this sort?
  6. Quick Sort (2 pts each)
    1. What is the worst case runtime for quicksort?
    2. Describe the cases that result in this runtime for quicksort:
    3. What is the average case runtime for quicksort?
    4. Describe the cases that result in this runtime for quicksort:
    5. Given the array below, trace quick sort. Circle the pivot(s) at each stage.
  7. Numerical Sorts (3 pts each)
    1. Name a sort that is not a comparison sort.
    2. What assumptions does this sort place on the range of elements to be sorted?
    3. What is the aymptotic run time of this sort?
  8. Describe the two major steps in implementing fsu::TBinaryTreeLevelorderIterator::operator ++() using the private data member fsu::CQueue < fsu::Navigator > Q;. (State answers in terms of Queue operations.) (10 pts)
  9. Use a stack to control depth first search:
    1. Declare a vector-based stack S of ValueType fsu::String: (5 pts)
    2. Illustrate the contents of the control stack S during a depth-first search of the tree tree2, beginning at vertex R = root and searching for the vertex goal. (Search left before right, beginning at the root, as conventional for trees.) (5 pts)