COP 4531 Practice Midterm Exam Fall 2007
- Heap Algorithms. Begin with the vector v = [ xx , xx , xx , xx , xx , xx ].
- Show the vector after v.PushBack(xx). (5 pts)
- Show the vector after fsu::g_push_heap(v.Begin(), v.End()). (Show
work.) (5 pts)
- 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
- O(1)
- Amortized O(1)
- O(log depth)
- O(depth)
- O(log size)
- O(size)
- O(size x log size)
- O(size2)
- None of the above
- Set Clients
- 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)
- 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)
- Sorts Theory (5 pts each)
- What is a comparison sort?
- What is the theoretical lower bound on the asymptotic worst case runtime
for a comparison sort?
- Give a short explanation of this fact.
- Comparison Sort (2 pts each)
- Name one comparison sort whose asymptotic worst case run time is at the
theoretical limit described above:
- What assumptions does this sort place on iterators defining the range to
be sorted?
- What is the asymptotic run space requirement of this sort?
- Quick Sort (2 pts each)
- What is the worst case runtime for quicksort?
- Describe the cases that result in this runtime for quicksort:
- What is the average case runtime for quicksort?
- Describe the cases that result in this runtime for quicksort:
- Given the array below, trace quick sort. Circle the pivot(s) at each stage.
- Numerical Sorts (3 pts each)
- Name a sort that is not a comparison sort.
- What assumptions does this sort place on the range of elements to be
sorted?
- What is the aymptotic run time of this sort?
- 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)
- Use a stack to control depth first search:
- Declare a vector-based stack S of ValueType
fsu::String: (5 pts)
- 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)