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

Discussion

Consider the following array.

2332456972738997
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order ?

  • A.Selection sort
  • B.Merge sort
  • C.Insertion sort
  • D.Quicksort using the last element as pivot

Answer: C

The algorithm with the fewest comparisons is insertion sort.

The array is already in ascending order. Insertion sort compares each new element only with the one before it, finds it already in place, and moves on, so it uses just n - 1 = 7 comparisons.

Selection sort always makes n(n - 1)/2 = 28 comparisons. Merge sort makes about n log n comparisons regardless of order. Quicksort with the last element as pivot hits its worst case on sorted input, also about 28 comparisons.

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

Post your comment

Please log in or register to post a comment.