Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Which structure finds the k-th largest element of a data stream after each insertion with O(log k) time per element and O(k) space?

  1. A. A min-heap of size k holding the k largest values seen so far
  2. B. A max-heap holding all elements
  3. C. A sorted array rebuilt on every insertion
  4. D. A hash set of all elements

Correct answer: A. A min-heap of size k holding the k largest values seen so far

A min-heap capped at size k keeps the k largest values; its root is the k-th largest element.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic