Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
david_allison
· 2y ago · 0 comments
It's O(n) if the array is already sorted, which is better than other n*log(n) CS101 algorithms (merge/heap/quicksort)
Comments
[–]
GuB-42
2y ago
Unless the element that should be at the start is at the end, everything else being sorted (ex: 2 3 4 5 6 1). Insertion sort is the best simple algorithm for almost sorted lists. In fact, it is generally considered the best O(n2) sorting algorithm.
[–]
dockd
2y ago
That's my memory from college: bubble sort is fine when the data is almost completely sorted.