Algorithms and Data Structures · Senior · Question 74 of 75

What does the "two heaps" trick fail to support efficiently, compared with a balanced BST?

Explanation

Heaps can only remove their root cheaply. For a sliding window median you need lazy deletion (marking removed values and skipping them later) or an ordered multiset, such as a balanced tree, that removes any value in O(log n).

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 74

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz