"Does these sorts algorithms (in Standard Library) use some of advanced sorts approaches, like bubble sort ... in their internal implementations."pic.twitter.com/G2aVVlqKBA
I guess you could have a smarter insertion sort that avoids memory writes if the element is already at the right place, though.
-
-
That's just the standard insertion sort. You go from left to right looking for a pair of elements that are out of order, and when you find one you swap the bigger element left until sorted. No writes if the array is already sorted.
-
I usually write the version that avoids swapping to bubble down elements, which does write in every iteration of the loop. Anyway, yeah, you’re probably right that insertion sort is just as good.
- 2 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.