CPSC 212, Test #2B, October 23, 2006

  1. How to explain why O(n log n) is the best performance possible for an algorithm that sorts by comparisons.

  2. B-Tree
             Leaf 1:  4  5  7
             Leaf 2: 15 16 19 23
             Leaf 3: 24 25 27
             Leaf 4: 29 34 36 43
             Leaf 5: 61 72 98
    
             Node 1: (parent of Leaf 1 and Leaf 2)
                     keys: 15
             Node 2: (parent of Leaf 3, Leaf 4, and Leaf 5)
                     keys: 29 61
             Node 3: (root and parent of Node 1 and Node 2)
                     keys: 24   
          

  3. Red-Black Tree

    A red-black tree is a binary search tree with the following red-black properties:

    1. each node is either red or black
    2. the root is black
    3. each leaf (NULL) is black
    4. if a node is red, its children are black
    5. every simple path from root to leaf has the same number of black nodes.

  4. Hash Table
             i:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18
             a:     1 20  2    39 21    78    58 40                77 59
          

  5. Leftist minHeap
                  root          : 15
                  children of 15: 19 16
                  children of 19: 27 23
                  children of 16: 24
                  children of 27: 61
                  children of 23: 34
                  children of 24: 29
          
  6. Binomial maxQueue
             Bo:  root          :  6
             B3:  root          : 27
                  children of 27: 24  7 19
                  children of  7:  5
                  children of 24: 23 15
                  children of 23:  4
          
  7. RadixSort
                     After Pass 1   After Pass 2
              1792      8710           4205
              4865      2190           8710
              2412      1792           2412
              2456      2412           2412
              8710      2412           1453
              2412      1453           2456
              4567      4865           4865
              1297      4205           4567
              1453      2456           2190
              2190      4567           1792
              4205      1297           1297
          
  8. QuickSort
             pivot = 41
             i: 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
             a: 19 29 39 25 28 41 91 95 63 46 43 57 77 63 72 63 69 48 86
          

  9. Why InsertionSort?
    For short arrays, i.e., arrays whose length is less than or equal to CUTOFF, InsertionSort will execute faster than QuickSort.

  10. Short Answers

    1. True
    2. False
    3. Separate chaining, Linear Probing, Quadratic Probing, Double Hashing
    4. HeapSort, MergeSort, QuickSort
    5. ShellSort