CISC 320 review sheet for first midterm exam.
Exam will be in class on Mar 17, 2000

Questions on this exam will be true/false, fill-in-blank, multiple choice, or short answer, for the most part. You might be asked to complete or modify the implementation of an algorithm.

Exam covers all material discussed in lecture and this reading:
Chapter 1 incl. insert sort and merge sort.
Section 4.3 solving recurrences using "master method"
Chapter 7 heap sort, heaps as priority queues
Sections 8.1 8.2 quick sort
Sections 10.1 10.2 median finding and selection of k-th element (randomized method)
Section 9.1 Decision tree proof that comparison based sorting requires Omega(n lg(n)) comparisons.
Scan Chapter 11 Elementary data structures (CISC 220 review).
Chapter 12 (excluding proofs) hash tables.
Scan Chapter 13 binary search trees
Chapter 14 Red Black Trees
Chapter 19 B-trees

Major categories of algorithmic problem:
Sort sequences (assuming random access): Achieve sorted order
Order statistic: find item of rank k, (eg. median is item of rank n/2).
Priority Queue: extract-min, insert
Dictionary: search, insert, delete

Major points about analysis: Worst case time, average case time, expected case time. Use of master theorem,

The old exam exam questions attached are not completely representative of what you can expect. Nonetheless they shows where the emphasis is on comparing the merits of various algorithms for sorting and dictionary search.

study guide (sample questions)

  1. Which sorting methods guarantee worst case time of O(n log(n)), for input sequence of length n?
  2. An element can be inserted in a heap by placing it at the end, increment n (the size of the heap) and calling upheap. What does upheap do?
  3. Which sorting method is particularly good on "almost sorted" sequences?
  4. Give a precise definition of "almost sorted" for the purpose of the preceeding question.
  5. Give an example of a case where sorting of an almost sorted sequence comes up.
  6. What sorting method we've studied is best on large "random" arrays?
  7. What sorting method is best on short arrays? How short?
  8. What disadvantage does mergesort have relative to quicksort?
  9. What disadvantage does quicksort have relative to mergesort?
  10. What is the maximum number of nodes in a B-tree of height 2 when t is 3?
  11. What is the minimum number of nodes in a B-tree of height 2 when t is 3?
  12. What is the range of depths at which leaves might occur in a red-black tree with 31 keys?
  13. What is the black death? Oh, sorry, that's medieval history 101.
    What is the black depth of a node in a red-black tree?
    What is the range of possible black depths of leaves in a red-black tree with 31 nodes?
  14. What does the "rotate" function do in red-black trees? Which of the basic dictionary functions call rotate in the red-black implementation?
  15. What advantage does a hash table have over a balanced tree for searching?
  16. what advantage does a balanced tree have over a hash table?
  17. which searching method guarantees each search, insert, and delete operation takes no more than O(log(n)) comparisons, on a dictionary containing n keys?

More questions (from previous semesters)

  1. How many vertices does a complete binary tree of height 6 have?
  2. Consider how many comparisons of elements would be made by insertion sort in each of these three arrays. Rank the array by how many comparisons would be made on it, with 1 indicating the array with the least comparisons, 2 middle, and 3 most.
    A = (11,21,31,41,51,61,71,81,91) Rank: ________
    B = (91,81,71,61,51,41,31,21,11) Rank: ________
    C = (91,11,81,21,71,31,61,41,51) Rank: ________
    Extra credit: calculate exactly how many comparisons insert sort would use on each.
  3. For simplicity suppose each comparison step (the inner loop body) in insertion sort requires 1 microsecond on a particular machine. Also suppose that each comparison step in the sort used in the STL requires 10 microseconds on the same machine.

    a) How long should we expect insertion sort to run on an array of size about one million (1,000,000)? ________

    b) a) How long should we expect the STL sort to run on the same array? ________

  4. For each of the following situations, which sorting method would most likely be the best. For each method briefly explain the main idea of the method.

    a) Each day the Weather Service receives a million weather station reports. It is essential that the data be sorted rather fast. However it is more important to be absolutely sure of being fairly fast than to be fairly sure of being really fast, with some data sets taking much longer. This is because the sort must be done in time to run the analysis program before the evening news. There is not enough memory on the computer to store two copies of the data set at once.

    b) The boss wants these records sorted and sorted now. She is hopping mad that this wasn't done yesterday. The world will not end if the data set happens to be bad for the method, but you get a big win if it is really fast and you suprise her with the quick turnaround. Again, there is not enough memory to store two copies of the data.

    c) This time there is lots of memory, but the dataset is so huge that even one copy of it doesn't fit in memory. Thus the data is on disk (or tape) and the sorted result must end on disk.

  5. Consider this implementation of mergesort.
    void mergesort(double A[], int firstindex, int lastindex)
    // sorts A[firstindex] thru A[lastindex]
    { if (firstindex < lastindex)
      { int midindex = (lastindex-firstindex-1)/2;
        mergesort(A, firstindex, midindex);
        mergesort(A, midindex+1, lastindex);
        merge(A, firstindex, midindex, lastindex);
        // merges A[firstindex]..A[midindex] with A[midindex+1]..A[lastindex]
      }
    }
    
    Consider the calls that would be made during this recursive process. For example, if X is an array of doubles, the call
      mergesort(X, 1, 3) 
    
    would involve the following function calls in the stated order.
        mergesort(X, 1, 2)
           mergesort(X, 1, 1)
           mergesort(X, 2, 2)
           merge(X, 1, 1, 2)
        mergesort(X, 3, 3)
        merge(X, 1, 2, 3)
    
    List the calls to merge in the order they are done in mergesort(X, 1, 10). Include the specific values for the indices in each call. You do not need to include the recursive calls to mergesort, though you may want to keep track of them in some way to help you get the merges right.
      merge(X,   ,    ,   )
      ...
    
  6. Draw the B-tree that results when a record with key G is inserted in this B-tree. Assume the variant of B-tree which stores only keys and links (pointers) in internal nodes and stores full records in external nodes. Assume there is room for 7 keys and 8 links (t = 4) in a page used as an internal node and room for 4 records in a page used as an exteranl node.
    
                 ___________  
                 | D I     |
                 -----------
    
    ___________  ___________  ___________  
    | A B C   |  | D E F H |  | I J K   |
    -----------  -----------  -----------
    

    saunders@cis.udel.edu