Sort algorithm choice is immaterial for small numbers

I was debating with myself whether I should do a time comparison for the sort algorithms. Then I decided other people had already explained it much better than I could (and the real reason was that I was too lazy to code it and measure it. But you didn’t hear it from me…). So I’ll tell you a story instead.

Manager at desk
[image by diane39]

It was a few years back. I was just a rookie programmer back then. My manager didn’t understand why his superiors hired me. I didn’t even have a proper degree in computer science. He seemed to think my degree in applied mathematics and computational science was irrelevant. In fact, I think he’s afraid of me on some level.

Every day, I walked into my cubicle, sat in my chair, and waited for the phone to ring off its hook. It was a boring existence, doing small maintenance code changes to the C source code, helping users with their queries and basically making sure the System continues to stand on its rickety feet.

I was too “lowly” to be given work in the frontend, the web programming parts, the “high value” work.

One senior colleague, relieved of the maintenance duties by me, got the chance to work on higher level design stuff. A new project arrived, Highly Perceptible Project Opportunity or HiPPO for short. The manager got 3 more new staff to help out. The backend programs would be done by one of the new staff and the senior colleague (since the business processing logic was entrenched there), and the frontend web application would be handled by the rest of the team.

Me? I was given the task of making sure the System continues to stand on its rickety feet. I was considered too “lowly” to handle high level design work or web application development, yet too senior and knowledgeable about the System to remove me from the System.

One day, while I was looking at an email trying to figure out what the user wanted, one of the web application developers came over to me. Let me repeat that. One of the web application developers came into my cubicle to talk to me! I barely even get to see anyone from the HiPPO team.

Anyway, Tyler (as I’ll call him) asked me if I knew anything about sorting. In particular, how to implement a sorting algorithm. What? I went over to Tyler’s computer (wow, I’ve never been in that area…) and took a look at his code, and what he needed to implement. I told him to send me the source code, and I’ll try something out first before getting back to him.

I went back to my desk, elated that I had something to work on other than update statements and Excel spreadsheets. Tyler sent me the source code (we didn’t have source control, and even if we had, I doubt I’d be given access), and I tried sorting using bubble sort.

After testing the results, the bubble sort implementation worked fine for the requirements, so I sent the code file back to Tyler. Tyler’s happy that the sort worked, and I went back to my boring existence.

The next day, my manager called me to go into his office. I went in, and he gestured me to sit down. He looked at me for a few seconds, a furrow forming between his eyebrows.

“Vincent, I heard from Tyler from this morning’s HiPPO project update that you helped him with his sorting implementation.”


He looked at me wordlessly for another few seconds.

“Is it fast? Have you looked at other sorting algorithms? There’s quicksort and heapsort I believe.”

My manager had obviously done his homework.

“Yes, I know of the other algorithms. I have chosen bubble sort because it’s easy to implement, and based on the requirements, it’s also fast enough.”

“I’m concerned about the speed. It has to be fast.”

“I’ve already tested with the higher ranges of the number of expected records. The performance is good. Tyler had also tested with the records from the test database, and it works fine.”

“But I’m worried about the user finding the web application slow.”

Now it’s my turn to look at him for a few seconds. I took a deep breath.

“We only need to sort maybe 3 or 4 records. Bubble sort is fast enough.”

[Story had been unbelievably distorted and exaggerated to make it interesting.]