Design a data structure to support the following two operations for a dynamic multiset S of integers,
Question:
Design a data structure to support the following two operations for a dynamic multiset S of integers, which allows duplicate values:
INSERT (S, x) inserts x into S.
DELETE-LARGER-HALF(S) deletes the largest ⌈|S|/2⌉ elements from S.
Explain how to implement this data structure so that any sequence of m INSERT and DELETE-LARGER-HALF operations runs in O(m) time. Your implementation should also include a way to output the elements of S in O(|S|) time.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Question Posted: