Examveda

Which sorting algorithm has a time complexity of O(n log n) in the worst case and is not stable?

A. Counting Sort

B. Heap Sort

C. Merge Sort

D. Quick Sort

Answer: Option B

Solution (By Examveda Team)

Heap Sort is a sorting algorithm with a worst-case time complexity of O(n log n). It is not stable because the relative order of equal elements may not be preserved during the sorting process.

Option A: Counting Sort is not correct because it has a time complexity of O(n + k), where k is the range of the input, and it is stable.

Option C: Merge Sort has a worst-case time complexity of O(n log n), but it is a stable sorting algorithm.

Option D: Quick Sort has an average-case time complexity of O(n log n), but its worst-case time complexity is O(n²). It is also not stable.

Therefore, the correct answer is Option B: Heap Sort, as it meets the criteria of O(n log n) in the worst case and is not stable.

This Question Belongs to Data Structure >> Sorting Algorithms

Join The Discussion

Comments (1)

  1. BeaT Me
    BeaT Me:
    9 months ago

    time complexity of quick sort is O(n2)
    so its answer should be heap sort
    heap sort time complexity is O(nlogn) and it's not stable also

Related Questions on Sorting Algorithms