Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following sorting does not have worst case running time of O(n\(^{2}\)) ?

  • A.Merger sort
  • B.Quick sort
  • C.Insertion sort
  • D.Bubble sort

Answer: A

Merge sort (printed 'Merger sort') does not have an O(n\(^{2}\)) worst case.

Merge sort always splits the list into halves and merges them in linear time, so its running time is O(n log n) in every case, including the worst.

Quick sort is O(n log n) on average but O(n\(^{2}\)) in the worst case, when pivots split the list very unevenly, as with already sorted input and a first-element pivot. Insertion sort and bubble sort are O(n\(^{2}\)) in the worst case, on reverse-sorted input.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.