Question:

Which sorting algorithm performs best for nearly sorted data?

Show Hint

Think which method makes almost no shifts when items are already close to place. Its best case is near linear.
Updated On: Jul 2, 2026
  • Bubble sort
  • Selection sort
  • Insertion sort
  • Quick sort
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Nearly sorted means most elements are already close to their final positions, so only a few small shifts are needed.

Step 2: Insertion sort picks each element and slides it left only until it meets a smaller element. If the data is nearly sorted, each element moves very little, often not at all.

Step 3: For an already-sorted or nearly-sorted array, insertion sort runs in close to linear time \(O(n)\), because the inner comparisons stop early.

Step 4: Selection sort always scans the full unsorted part regardless of order, so it stays \(O(n^2)\). Bubble sort can detect sortedness but still does more work per pass. Quick sort does not benefit from near-sortedness and can even degrade. Insertion sort is the best fit, so the correct option is (C).
Was this answer helpful?
0
0