CISC 320 Algorithms and Advanced Programming, Spring 2001, Saunders
First midterm exam

Curve: Take raw score r (written on graded exam) and compute c = 10*sqrt(r+10). Compare this c to standard thresholds:
r   c   letter
71  90  A
54  80  B
39  70  C
26  60  D

Name: Answer key

Multiple choice problems (2 points each)

  1. C.     O(lg(n)) < O(n) < O(n*lg(n)) < O(n2) < O(2n)

  2. D.     Heap sort and mergesort

  3. D. n! leaves.

  4. B. to determine the k-th smallest element in an array for given array and k.

  5. D. None of the above

  6. B. n2/2

  7. A. It rearranges the array somewhat.

  8. C. Both A and B.

  9. C. Provably, any algorithm that solves the problem must use at least about n + lg(n) comparisons.

  10. D. All of the above.

  11. A. randomizedSelect has the fewer comparisons in practice (average/expected number of comparisons).

  12. A. Has an expected case number of comparisons E(n) which is O(n).

  13. D. None of the above

  14. A. both Boyer-Moore and Knuth-Morris-Pratt algorithms require no more than O(nm) comparisons.

  15. C. When the data is dynamic, with many insertions/deletions of items as well as look-ups.

  16. C. between 16 and 256

  17. C. no node has two red children

  18. A. the colors of a black node and it's two red children are flipped.

  19. C. a temporary situation in which a red node has a red child is fixed.

  20. B. 2

  21. D. 10

  22. B. O(lg(n))

  23. B. O(lg(n))

  24. B. O(lg(n))

  25. D. Neither A nor B

  26. A. Insertion sort


  1. (8 points) In Boyer-Moore string searching, consider this text and pattern: (the line of numbers is just to help you identify positions)
      |
      v
    123456789 123456789 123456789 123456789 123456789 123456789 12345
    no analog of asymptotic complexity exists in research on bananas.
    banana
    
       banana (next position on basis of charjump)
      banana (next position on basis of matchjump)
       banana (next position chosen - best of the two)
    
    19 comparisons are made.  Compared chars are in caps (_ for blank):
    no_ANAloG of aSymptoTic coMplexiTy exiSts in_reseaRch on_BANANAs.
    baNANA
       bananA 
             bananA 
                   bananA 
                         bananA 
                               bananA 
                                     bananA 
                                           bananA 
                                                 bananA 
                                                       bananA 
                                                             BANANA 
    

  2. (10 points) A.

    W(n) = n + sum from i = 2 to n-1 of lg(i). B.

    W(n) = about n + n*lg(n) = about n*lg(n) = O(n lg(n))

  3. (20 points) Write two of the following three algorithms

    Solution: consult text or online samples.

  4. (10 points) Introspective is quickSort except that when the region size to be sorted is small (say less than 20 or so), insertionSort is used. A depth of recursion counter is used also. When the depth exceeds a threshold such as 2lg(n), then heapSort is used. Thus the guarantee of worst case performance O(n*lg(n) ) is achieved while getting the best of quick sort and insertion sort.