Explain why: The selection sort may do slightly better when data is already sort
ID: 3534446 • Letter: E
Question
Explain why:The selection sort may do slightly better when data is already sorted.
The insertion sort may do significanly better when data is already sorted
(i.e. why its improvement is better than selection sort's)
The quick sort may do significantly worse when data is already sorted
Explain why:
The selection sort may do slightly better when data is already sorted.
The insertion sort may do significanly better when data is already sorted
(i.e. why its improvement is better than selection sort's)
The quick sort may do significantly worse when data is already sorted
Explanation / Answer
ccording to these benchmarks in C# comparing the built-in quicksort to TimSort, Timsort is significantly faster in the mostly sorted cases, and slightly faster in the random data case and TimSort gets better if the comparison function is particularly slow. I haven't repeated these benchmarks and would not be surprised if quicksort slightly beat TimSort for some combination of random data or if there is something quirky in C#'s builtin sort (based on quicksort) that is slowing it down. However, TimSort has distinct advantages when data may be partially sorted, and is roughly equal to quicksort in terms of speed when the data is not partially sorted.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.