2 ms·
> just being able to write stock algorithms correctly without much thought Outside of a job interview, I don't see why this would be a good idea. If you need a
by jacques_chester 13y ago
> just being able to write stock algorithms correctly without much thought
Outside of a job interview, I don't see why this would be a good idea. If you need a stock algorithm and your environment has a stock implementation, why on earth would you roll your own umpteen zillionth implementation?
Sometimes you have an embedded problem or some weird feature of the problem domain that favours a non-stock algorithm. But that surely suggests only knowing algos to the depth required to pass Algorithms 202 ("this is an odd case, I'll look up the alternatives"), not having muscle memory that can instantly spray plain mergesorts into a text editor.
- anonymoushn 13y agoI am not talking about writing a sort. When it comes to providing stock algorithms, most environments are woefully inadequate. I have not yet encountered an environment with a usable maximum_bipartite_matching(), ternary_search(), or bfs(). To be usable, it would need to be easier to convert my problem instance into the types accepted by the library function than to write the code that does the right thing on my types. STL's next_permutation() is the only next_permutation() in any environment I am familiar with, and it does a great job. I believe I've also encountered one stock implementation of binary search that is useful for the case of "binary searching on the answer" (rather than just binary searching in an array), but this isn't a big deal because it saves you maybe 3 LOC.
- jacques_chester 13y agoYou and I have different concepts of stock. I'd be amazed if 80% of what's required in practice isn't all boiling down to search & sort. They're baked into damn near everything, either explicitly or by indirect usage. I don't really know or care which exact elaboration of quicksort that my database engine is using. I'd be unsurprised if there aren't a few that it chooses amongst at plan time. I just say ORDER BY and get on with the rest of my work. Alternatively I could pull the unordered set and write my own sort. And I'd hope to be committed to an institution for the criminally wasteful for such an act.
- hackinthebochs 13y agoThe problem with reasoning like this is the implicit assumption that getting better at X does not carry over into performing Y. I promise you, if you memorized the top 100 computer algorithms by heart, you would absolutely come out a better programmer. Why? Memorizing computer science algorithms is not like memorizing a random string of numbers. Each unit is connected to other units which strengthen your recall and understanding of completely unrelated algorithms and concepts. Our brains organize information in a hierarchical fashion, and when we learn some algorithm we are strengthening our recall and understanding (connections to other concepts) of the basic building blocks of the algorithms. So, for example, while you may never need to roll your own quicksort, the concept of partitioning a set of items based on a pivot is a fundamental concept that will be re-enforced in the process.