Return to main page


Design and Analysis of Algorithms

CMSC 441 - Fall 2021


Homework 3

Due: Wednesday, October 20th by 11:59:00 PM EDT (on blackboard)

Musical Selection: Nocturne Op. 9 No. 2 in E flat major — Frédéric Chopin

Respond to the questions below with appropriate responses as directed.

  1. (20 points) Using the code provided in class or in the textbook for the Max-Heapify function as a model, provide pseudocode for a Min-Heapify function which performs the corresponding actions on a min-heap. Provide a recurrence describing the running time of Min-Heapify and the solution to the recurrence and justify your solution appropriately (either by using the master theorem or the substitution method).
  2. (10 points) Argue the correctness of Heapsort (as provided in the book or in class) with the following loop invariant:
    At the start of each iteration of the for loop, the subarray A[1 ... i] is a max-heap containing the i smallest elements of A[1 ... n], and the subarray A[i+1 ... n] contains the n-i largest elements of A[1 ... n], in sorted order.
  3. (20 points) Determine the running time for the non-randomized version of Quicksort when run on an array containing distinct elements sorted in decreasing order. Explain your answer based on how the Partition function divides the work.

Questions adapted from "Introduction to Algorithms" 3rd edition.
Last modified Wednesday, 13-Oct-2021 21:01:32 EDT