CISC 320 Algorithms and Advanced Programming, Spring 2001
Crib sheet for first midterm
Midterm exam date: March 13, 2001
Note: This exam is worth 22% of the course grade.
Getting a start on the homework is good preparation, since it leads to
review of relevant material.
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.
Textbook Reading material covered
Chapter 4.2: Insertion sort
- Be able to write code for insertion sort.
- Be able to write recurrence relation or summation formula and know asymptotic complexity.
- know asymptotic complexity.
Chapter 4.3, 4.4: Quick sort and randomPartition
- Be able to write code for partition and for quick sort using partition.
- know asymptotic complexity.
Chapter 4.5, 4.6: Merge sort and merge
- Be able to write code for merge and for merge sort using merge.
- Be able to write recurrence relation and know asymptotic complexity.
Chapter 4.7: Comparison based sorting lower bound argument.
- 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 order n*lg(n).
Chapter 4.8: Heap sort and heaps
- Understand relation between perfect tree and storage scheme in array.
- know asymptotic complexity.
Chapter 4.9: 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 write introspective sort.
Chapter 5.2: Finding max and min. 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.
Chapter 5.3: Finding second largest. 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.
Chapter 5.4: selection problem and median finding.
- know how probabilistic algorithm based on randomPartition works
- know that expected case number of comparisons is O(n).
Chapter 6.4: Red-Black trees.
- know what properties of red-black trees are maintained by
all the operations.
- 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
lg(n) and black depth at most about lg(n)/2
- Know how 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.
Chapter 11.3: Knuth Morris Pratt algorithm.
-
Know how far the pattern shifts when a mismatch occurs.
- Know that the comparison position in the text never moves back.
- Know the worst case complexity.
Chapter 11.4: Boyer Moore algorithm.
-
Know how far the pattern shifts when a mismatch occurs.
- Know how far each of the heuristics would shift on it's own.
- Know the worst case complexity.
Types of questions to expect:
- Multiple choice questions as illustrated in an earlier
handout.
- Short answer questions such as these.
-
Which sorting method is especially good on short arrays (say 10 elements)?
________________
- In Boyer-Moore string searching, when the pattern "freedom" is searched for in the text of this sentence,
what is the first comparison made? ___________ The second? ___________.
- 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 . quickSort(A, s, e) 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,
void mergeSort(comparable A[], int s, int e)
{ int n = e - s;
if (n < 2) return;
int q = (n+1)/2;
mergeSort(A, s, q);
mergeSort(A, q, e);
merge(A, s, q, q, e, B);
copy(B, n, A + s); // copy n things B[0..n) to A[s..e).
}
-
(bunch of points)
Assuming merge(A, s1, e1, s2, e2, B) requires at most (e1 - s1) + (e2 - s2)
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