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)
  • Quick sort and randomPartition (Ch 4.3)
  • Merge sort and merge (Ch 4.1)
  • Comparison based sorting lower bound argument (Ch 4.4)
  • Heap sort and heaps (Ch 2.4)
  • Comparisons among the 4 methods
  • Introspective sort: combining the methods (no coverage in text)
  • Finding max and min. (no coverage in text) Alg and lower bound.
  • Finding second largest. (no coverage in text) Alg and lower bound
  • Selection problem and median finding (Ch 4.7.2)
  • 2-4 trees and Red-Black trees (Ch 3.1, 3.3)
  • Union-find, dynamic partitions (Ch 4.2)
    Types of questions to expect:
    1. Multiple choice questions.
    2. Short answer questions such as this.
      1. Which sorting method is especially good on short arrays (say 10 elements)? ________________
    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 . randomizedQuickSort(A, s, e), which 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,
      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).
      }
      
      1. (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.
      2. (fewer points) Up to bigO, what is a solution to this recurrence?

    saunders@cis.udel.edu