R
Richard Tobin
user923005 said:You will have to adjust the (K-element) heap for every element in the
list (e.g. one billion of them, less 1000).
This involves at least two operations:
1. Adding a new element. (Constant time, so this just affects the
constant of proportionality)
2. Removing the max element. (This requires a re-balance and is not
O(1)).
It may depend on K, but K is a constant (1000). The time to rebalance
does not depend on N.
(And you don't have to adjust the heap for the vast majority of the
billion items, since they will almost all be smaller than the current
smallest heap item.)
-- Richard