exe that took a list of numbers, turned them into an array, and called my sorting function, printing the result.
Selection sort vs bubble sort graph how to#
I separated my sorting routines into a DLL (I’m learning how to do Windows programming - it’s pretty different from Unix).Create a good test harness that makes it easy to test. I found and fixed bugs in all of my initial sorts.Mocking up the problem on paper is crucial, just like writing the code to swap items in a linked list.They can be faster for sorting small data sets ( vs >= as you try to avoid walking off the end of the array with a swap. real time - The simple algorithms may be O(N^2), but have low overhead. Caching - algorithms with sequential comparisons take advantage of spatial locality and prefetching, which is good for caching.For security, you want the guarantee that data from an attacker does not have the ability to overwhelm your machine. Worst-case behavior is important for real-time systems that need guaranteed performance.Factors: algorithmic complexity, startup costs, additional space requirements, use of recursion (function calls are expensive and eat stack space), worst-case behavior, assumptions about input data, caching, and behavior on already-sorted or nearly-sorted data.One technique is to start with a “sorted list” of one element, and merge unsorted items into it, one at a time.You rescan, moving items closer to the final position with each iteration. Some algorithms (insertion, quicksort, counting, radix) put items into a temporary position, close(r) to their final position.You sort an array of size N, put 1 item in place, and continue sorting an array of size N – 1 (heapsort is slightly different). Some algorithms (selection, bubble, heapsort) work by moving elements to their final position, one at a time.I had an itch to review the algorithms in Wikipedia (strange, I know), and here are my notes: High-level thoughts Sorting is a key to CS theory, but easy to forget. (Still a work-in progress I want to revisit with intuitive explanations and playing-card examples)