The Median Maintenance Problem

From NovaOrdis Knowledge Base
Revision as of 22:28, 9 October 2021 by Ovidiu (talk | contribs) (→‎Problem)
Jump to navigation Jump to search

Internal

Overview

The median maintenance problem is a canonical use case for a heap.

Problem

Give a sequence of numbers x1, x2, .... xn, report at each step the median number of numbers seen so far.

Discussion

The problem can be resolved by solving the selection problem on the set of numbers seen so far, but the selection problem has a running time of O(n), so repeating the selection algorithm for each number will have a running time of O(n2).