Repository navigation
|
For the sorting algorithms implemented in this repo, which one should be preferred for nearly-sorted input, and why? |
Answered by
Kubomu
Jul 11, 2026
Replies: 1 comment
|
For nearly-sorted input, insertion sort (O(n) best case) outperforms the general-purpose O(n log n) sorts here since it adapts to existing order — quicksort/mergesort pay their full O(n log n) cost regardless of initial ordering. |
0 replies
Answer selected by
Kubomu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For nearly-sorted input, insertion sort (O(n) best case) outperforms the general-purpose O(n log n) sorts here since it adapts to existing order — quicksort/mergesort pay their full O(n log n) cost regardless of initial ordering.