Heaps are a
fundamental data structure that implement the priority queue
abstract data
type. Essentially,
a priority queue is one where the element at the front of line is
always the one of highest priority, which is defined by the
programmer for a specific implementation. A standard heap
implementation provides fast access to the front element of the
queue, in O(1) time, as well as insertion/deletion in
O(log(n)) time.
Usually, the highest priority value is defined as either the minimum
or maximum value in the data, as implemented in min and max heaps
respectively. In this post, however, we will look at a more
specialized heap that instead prioritizes the median value. Why
would this be useful? I'm not sure of any practical applications,
but assumedly it could be if it were ever performance critical to
repeatedly calculate the median. Let's jump in.