UMBC CMSC441, Design & Analysis of Algorithms, Fall 2014


Homework 4

Due Thursday, September 25, 2014

Important instructions: Please do not use pseudocode (or actual code) to present your algorithm. Give a high-level description using complete English sentences in paragraph form. Resort to pseudocode only if implementation details are needed to justify the correctness or the running time of your algorithm. Finally, pseudocode must be commented, just like regular code.

  1. Merging k sorted lists. Exercise 6.5-9, page 166.

  2. Best Case Running Time of HeapSort For this question, we want to show that the best case running time of HeapSort is Ω(n log n). That is, we want to argue that there is no "lucky" case for HeapSort. In comparison, InsertionSort has a lucky case: if the array is already sorted, then InsertionSort runs in linear time. Your answer to this question should convince others that there is no such "lucky" case for HeapSort.

    Assume that the items we want to sort are all distinct and are valued 1, ..., n. Let BIG denote the bigger half of these numbers. That is,

    BIG = { n/2, n/2 + 1, ..., n }.

    Answer the following questions. Provide a brief explanation for each of your answers.

    1. When will the items in BIG be removed from the heap during the execution of HeapSort?
    2. Initially, how many items in BIG can be at the bottom level of the heap, after the build heap phase of HeapSort? (Recall that we are using a max heap.)
    3. Initially, how many items in BIG can be within the top (log n)/4 levels of the heap, after the build heap phase of HeapSort?
    4. Let X be the items in BIG which are neither in the bottom level initially nor within the top (log n)/4 levels initially. At least how many items are in X?
    5. At least how much time will HeapSort spend on items in X?
    6. Argue that the best case running time of HeapSort is lower bounded by Ω(n log n).

  3. Special index. You are given a sorted array of n distinct integers A[]. (Here "distinct" means that no integer appears in the array twice.) Describe an algorithm that determines whether there is an index i such that A[i] holds the integer i. (Note: integers can be negative.)

    Your algorithm should either report the value i or say that no such i exists. Make your algorithm as fast as you can.


Last Modified: 17 Sep 2014 10:43:42 EDT by Richard Chang
to Fall 2014 CMSC 441 Section 2 Homepage