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
  • Chapter 4.3, 4.4: Quick sort and randomPartition
  • Chapter 4.5, 4.6: Merge sort and merge
  • Chapter 4.7: Comparison based sorting lower bound argument.
  • Chapter 4.8: Heap sort and heaps
  • Chapter 4.9: Comparisons among the 4 methods
  • Introspective sort: combining the methods (no coverage in text)
  • Chapter 5.2: Finding max and min. alg and lower bound
  • Chapter 5.3: Finding second largest. alg and lower bound
  • Chapter 5.4: selection problem and median finding.
  • Chapter 6.4: Red-Black trees.
  • Chapter 11.3: Knuth Morris Pratt algorithm.


  • Chapter 11.4: Boyer Moore algorithm.
    Types of questions to expect:
    1. Multiple choice questions as illustrated in an earlier handout.
    2. Short answer questions such as these.
      1. Which sorting method is especially good on short arrays (say 10 elements)? ________________
      2. 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? ___________.
    3. Short essay questions such as this.
      1. Explain in a few sentences how heaps work.
    4. 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).
    5. 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).
      }
      
      1. (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.
      2. (fewer points) Up to bigO, what is a solution to this recurrence?

    saunders@cis.udel.edu