- Banned
- #1
- Dec 24, 2013
- 394
- 296
And realized that the manner he was switching the keys resembled sorting an array.
The keys are arranged in columns of four (4) up to seven (7) rows. Each key is identified with a numeric index; ideally, they are arranged in order. Sometimes, work gets hectic: as keys come in and out, new keys with larger numeric indices may become inserted at the first space available, leaving the rows unsorted. Therefore, the manager gets mad and has to sort the keys again (or I do it, because I become equally as mad).
However, as I observed him switching - or, sorting - the keys, it resembled a technique called insertion sort. The keys are nearly sorted, and thankfully not randomly ordered. As a result, this technique is faster than methods such as heap sort which would have better average-case performance (and worst-case performance) than insertion sort for random containers (and even clearer, reversed containers).
I forget: Here's a pythonic program I wrote demonstrating this. Try it out with various arrays. Here's the main program you use.
The keys are arranged in columns of four (4) up to seven (7) rows. Each key is identified with a numeric index; ideally, they are arranged in order. Sometimes, work gets hectic: as keys come in and out, new keys with larger numeric indices may become inserted at the first space available, leaving the rows unsorted. Therefore, the manager gets mad and has to sort the keys again (or I do it, because I become equally as mad).
However, as I observed him switching - or, sorting - the keys, it resembled a technique called insertion sort. The keys are nearly sorted, and thankfully not randomly ordered. As a result, this technique is faster than methods such as heap sort which would have better average-case performance (and worst-case performance) than insertion sort for random containers (and even clearer, reversed containers).
I forget: Here's a pythonic program I wrote demonstrating this. Try it out with various arrays. Here's the main program you use.
Dislike ads? Remove them and support the forum:
Subscribe to Fastlane Insiders.