CPSC 327 Data Structures and Algorithms Spring 2024

Comments on Homework 9

  1. You wish to store a set of n numbers in either a max-heap or a sorted array.

Explain the idea in words. Sometimes pseudocode can then be useful to clarify details, but code is never useful and pseudocode should be carefully considered — too many details obscures the idea rather than explaining it.

"Form the structure quickly" (part c) refers to building the max heap or sorted array from a collection of the n numbers — they are all known. Something to keep in mind here is whether there is something more efficient than inserting elements one at a time. For heaps, remember the heapify operation.

A series of n O(log n) operations is O(n log n).