Data Structures & AlgorithmsModerateTCS NQT · sorting

Problem: What is the worst-case complexity of Heapsort on n elements?

  1. A. O(n^2)
  2. B. O(n)
  3. C. O(log n)
  4. D. O(n log n)

Correct answer: D. O(n log n)

Each of the n extract-max steps costs O(log n), and heap construction is O(n).

More Coding Interview Problems questions

Exams that ask this topic