Retaining the fastest readings in a stream

A response-time logger retains the five smallest readings seen so far using a binary heap containing exactly five readings. It has already processed 6262, 4545, 5757, 2828, and 39 ms39\ \text{ms}, and all five are currently retained.


The logger then receives these readings in order:


51, 66, 34, 22, 49, 30 ms.51,\ 66,\ 34,\ 22,\ 49,\ 30\ \text{ms}.


Choose either a min-heap or a max-heap so that each new reading can be accepted or rejected by comparing it only with the root. Whenever a reading belongs among the five smallest seen so far, replace the root with that reading and restore heap order. Otherwise, discard the new reading. All readings are distinct.


Report the required heap type, the total number of root replacements during these six arrivals, and the largest retained response time after all arrivals. Enter the replacement count as an exact integer and the response time in milliseconds to zero decimal places.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Heaps Questions: