News for hackers. Stuff that matters.
Re:Why is quicksort better than other sorting algorithms in ... by ska on Monday January 20, 2020 @03:06PM (#22101704)
Early algorithm development thought about this quite a bit because system memory was really constrained.
Re:Why is quicksort better than other sorting algorithms in ... by mark-r on Monday January 20, 2020 @04:47PM (#22102344)
This reminds me of the first task I had at a new job. The company had a cross-assembler for their custom processor that ran on a PDP-11 with a 65KB total task space. I was told to add an option to turn off the cross reference output, because it was taking 30 minutes to add it to a 2 minute assembly run.

Before starting I decided to figure out why the cross reference was taking so long. Each reference was added to a dynamic memory array, until the memory was filled and then the references were written to a disk file instead. At the end of the assembly, the array was sorted with a Bubble sort. Then for each symbol in the symbol table, the table and file were read linearly to find each reference for that symbol. This was an O(n^2) process - no wonder it was so slow!

I took out the Bubble sort and did a Merge sort on the file, then read the file to create the cross reference directly since it was in the proper order. When the time went from 30 minutes to 30 seconds, suddenly it wasn't important to have an option to turn it off anymore.