CISC 320 Algorithms and Advanced Programming, Fall 2002
Crib sheet for first midterm
Midterm exam date: Tue, Oct 15, 2002
Note: This exam is worth 20% of the course grade.
Below when I say "be able to write code" I mean be able to write
C++ or Java or similar pseudocode that makes the algorithm clear and
gets the details right or nearly right.
I may ask you to set up a
recurrence relation or summation formula. I may ask you to give a function
that is an estimate of the worst case or average case complexity of an
algorithm, hence is an estimate of the solution of a recurrence or summation.
But I never will ask you to derive the solution to a recurrence
or summation.
I may write an easy or a hard test. I always apply a curve to a test
which is an adjustment for my evaluation of it's difficulty after seeing
your results.
Thus it is in your interest not to get discouraged and to answer as fully
as you can. A low overall score may turn out to be a lot better than you
expected.
It is in your interest to answer so as to express what
you know about a problem even when you cannot give a complete answer.
Material covered
Insertion sort (Ch 2.4)
- Be able to write code for insertion sort.
- Be able to write recurrence relation or summation formula and know asymptotic complexity.
- know asymptotic complexity of insertion sort.
Quick sort and randomPartition (Ch 4.3)
- Be able to write code for partition and for quick sort using partition.
- know average and worst case asymptotic complexity of the quicksorts.
Merge sort and merge (Ch 4.1)
- Be able to write code for merge and for merge sort using merge.
- Be able to write recurrence relation and know asymptotic complexity.
Comparison based sorting lower bound argument (Ch 4.4)
- Understand the idea of a decision tree corresponding to an algorithm
- Be able to explain why a sorting algorithm's decision tree must have
at least n! leaves.
- Know that that implies a depth of of the decision tree of order n*lg(n).
Heap sort and heaps (Ch 2.4)
- Understand relation between perfect tree and storage scheme in array.
- know worst case asymptotic complexity of heap sort.
Comparisons among the 4 methods
- worst case, average case, expected case complexities.
- additional properties: memory needs, small arrays,
- parts that have other uses: partition, merge, heaps.
Introspective sort: combining the methods (no coverage in text)
- be able to explain how introspective sort works.
Easiest way: be able to write pseudocode of introspective sort.
- be able to explain why and how introspective sort is an
improvement over the other sort algorithms.
Finding max and min. (no coverage in text) Alg and lower bound.
- understand how code works that would find max and min in about
3/2n comparisons.
- understand the adversary argument that max requires n-1 comparisons.
Finding second largest. (no coverage in text) Alg and lower bound
- understand how code works that would find second largest in about
n + lg(n) comparisons. The use of a heap to represent a tournament.
- Understand the argument that second largest requires about n + lg(n)
comparisons.
Selection problem and median finding (Ch 4.7.2)
- know how probabilistic algorithm based on randomPartition works
- know that expected case number of comparisons is O(n).
2-4 trees and Red-Black trees (Ch 3.1, 3.3)
- know what properties of red-black trees are maintained by
all the operations. (a) no two red edges in a row on a path to the root,
(b) all leaves are at the same black depth.
- know that each insertion, search, or deletion can be done in
O(lg(n)) comparisons when done on a red-black tree with n nodes.
- Know that a red-black tree with n nodes has depth at most about
2lg(n).
- Know how red-black insertion works in the sense that you could take
a diagram of a red-black tree and a key to be inserted, and draw a
diagram of the resulting red-black tree.
Union-find, dynamic partitions (Ch 4.2)
- Know the basic data structure (a forest of trees, each
item simply having a parent pointer).
- Know how the union-by-weight heuristic works.
- Know how the path-compression heuristic works.
- Understand what an amortized analysis is (Ch 1.5).
- Know that union-find has amortized cost of lg*(n) per
user union or find operation in a sequence of n ops.
- Know what the lg* function is and appreciate it's
extremely slow growth.
Types of questions to expect:
- Multiple choice questions.
- Short answer questions such as this.
-
Which sorting method is especially good on short arrays (say 10 elements)?
________________
- Short essay questions such as this.
-
Explain in a few sentences how heaps work.
- Questions that ask you to write an algorithm such as:
- Write the randomizedPartition procedure used in quick sort.
randomizedPartition(A, s, e) swaps elements as necessary and
returns a q in [s..e-1) such that
A[s .. q) < A[q .. e)
- Assuming randomizedPartition has been written as described above, write the
quickSort procedure . randomizedQuickSort(A, s, e), which sorts A[s..e).
- Questions which ask you to look at code and then to write a
recurrence relation or summation expressing it's compute time.
For example,
template
void mergeSort(Ptr b, Ptr e, Ptr w)
{ int n = e - b;
if (n < 2) return;
Ptr q = b + n/2;
mergeSort(b, q, w);
mergeSort(q, e, w);
merge(b, q, q, e, w);
copy(w, w + (e-b), b); // copy w[0..n) back to b[0..n).
}
-
(bunch of points)
Assuming merge(b1, e1, b2, e2, w) requires at most (e1 - b1) + (e2 - b2)
comparisons, write a recurrence relation expressing the worst case number
of comparisons used in mergeSort.
-
(fewer points)
Up to bigO, what is a solution to this recurrence?
saunders@cis.udel.edu