2 ms·
Quicksort is a wonderful example of an algorithm that's really simple, but that gets mired up in implementation details to the point of being unrecognizable. Th
by thequux 15y ago
Quicksort is a wonderful example of an algorithm that's really simple, but that gets mired up in implementation details to the point of being unrecognizable. The fundamental insight of quick sort is that you partition the list into items smalller than a given value and items larger than that value. Then you just sort the subitems.
Most algorithms are similar; there's a core idea and then a bunch of implementation around it. My advice for dealing with that is to build up a library of routines that you know the complexities of, and then use those to build more complex algorithms.
Unfortunately, I'm not in a good environment to write code right now, but I'll give an example of how that might work when I get home.
In terms of reference material, check out CLRS