CPSC 289: Data Structures & Algorithms
Information and Review Questions for Exam 2
Spring 2009


General Information

The second exam will be on Tuesday April 7, 2009. It will cover material from Chapters 8, 9, and 10 in the text. It will be a closed book exam (no notes, books, or neighbors) except you will be allowed a one page (8.5x11), two-side cheat sheet which must be turned in with the exam. There will be 5 questions, each worth 20 points, for a total of 100 points. Remember to show your work - partial credit will be given.


Material

All of the following are considered to be fair game:


Review Questions

Below are some suggested review exercises/problems for the exam. It is strongly recommended that you be able to do all of these problems. Solutions will not be handed out. Finally, be sure to check your email -- clarifications and/or explanations will be mailed to the class if needed.

  1. Study Homeworks 5-7, Quizzes 5-7, and the in class assignments; variations of some of these questions will appear on the exam.

  2. Hashing. Consider inserting the following keys, in this order, into a hash table of size m=13.

    keys to insert (in this order): 9, 1, 22, 14, 27

  3. Search Trees.

  4. Sorting. Consider the following comparison-based sorting algorithm.
    Fast-Sort(array L of integers)
     if (L has less than 4 elements)
       then sort L by brute-force and return L;
       else 
          L1 := Fast-Sort(1st quarter of L);
          L2 := Fast-Sort(2nd quarter of L);
          L3 := Fast-Sort(3rd quarter of L);
          L4 := Fast-Sort(4th quarter of L);
          L := 4-way-Merge(L1,L2,L3,L4);
          return L;
     endif 
    end /*Fast-Sort*/
    

    Assume the complexity of 4-way-Merge(L1,L2,L3,L4) is O(n1 + n2 + n3 + n4), where ni is the number of elements in Li, i=1,2,3, 4. Derive and solve the recurrence relation for the asymptotic running time of Fast-Sort; clearly state any assumptions you make. (You don't have have to solve the recurrence relations for exam 2 because you are only just starting to cover them in discrete math now.)

  5. Sorting. Suppose you are given a list of n integers to sort that contains only the values 1, 2, 3, and 4. Consider how the presence of duplicate elements affects the running time.

    1. Suppose you use insertion sort.
      What is the absolute number of comparisons (approximately) that will be done in the worst-case, and how does this compare to the situation in which all n elements are distinct?
      What is the order of the number of comparisons that will be done in the worst-case, and how does this compare to the situation in which all n elements are distinct?

    2. Is radix sort a good algorithm to use in this situation? Why or why not?

    3. Is there an in-place algorithm for this problem that runs in O(n) time? If not, explain why not. If so, give the algorithm.