Multiple choice technology programming languages

Which of the following sorts is quickest when sorting the following set: 1 2 3 5 4

  1. Bubble Sort

  2. Quick Sort

  3. Merge Sort

  4. Radix Sort

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

For the nearly-sorted array [1,2,3,5,4], Bubble Sort only needs one pass to swap 5 and 4, completing in O(n) time. More complex sorts like Quick Sort have overhead that makes them slower for small, nearly-sorted datasets. This illustrates that 'fastest' depends on initial data state.