The worst-case time complexity of heapsort is ___________.

  • O(log n)
  • O(n log n)
  • O(n)
  • O(n^2)
The worst-case time complexity of heapsort is O(n log n). Heapsort involves two main operations: building a heap (heapify) and repeatedly removing the maximum (for a max heap) or minimum (for a min heap) element. Both of these operations have a time complexity of O(n log n) in the worst case, resulting in heapsort also having a worst-case time complexity of O(n log n). This makes heapsort an efficient sorting algorithm for large datasets.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *