Wait.
Do you, really?
The only people who can do this off the top of their heads are
- People who write sorting algorithms in their day-to-day job
- People who recently encountered a performance issue in their code and thought it might be down to the choice of sorting algorithm
- People with a genuine interest in sorting algorithms
- Recently graduated university students
- People who've just been asked to do it in a whiteboard interview and have vowed to not make the same mistakes next time
These are scientifically ranked in ascending order of likelihood.
Notice I didn't mention "people who need to know which is the best sorting algorithm to use in a given situation", because those people don't need to know how to write a sorting function. Those people will use an existing sorting function which has been written and optimised a long time ago.
In fact, most developers can go their entire career without even needing to know what algorithm is being used when they call a generic sort()
function. It's far more likely that you'll need to know how to get the data in a useful order in the first place if it comes to that, so knowing about indexes on an RDMBS might be handy.
Knowing about Big O might be handy, or at least knowing what it is, even if you can't go into detail. To me, knowing there is a difference is more important than knowing what that difference is. Knowing how to research it at the time is more important still.
So if you attend an interview and someone asks you to write a particular sorting algorithm, ask them whether anyone has ever had to do that in their role at that particular company.
And if they can't answer, then your response can just be, "I'll Google it when the time comes."
--
Cover image by Sophie Elvis on Unsplash