Do you memorize algorithms such as binary search / quick sort / whatever. If so, do you have any tricks for doing so?
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to get a fixed number of evenly spaced points
- Space complexity of validation of a binary search
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- How to measure complexity of a string?
- Select unique/deduplication in SSE/AVX
- How to smooth the blocks of a 3D voxel world?
Seek to comprehend instead of memorizing. I find it helps me to work through proofs of an algorithm to get the inner workings of what's going on, and that's usually proven to be good mnemonic strategy.
I would never risk trying to memorize these - always try to find a library function which handles it.
You should know the general principles behind these algorithms because they are the fundamentals of programming and it will give you insight into where they should be used. For example, you should understand quick sort well enough to understand why it can be O(N^2) in pathological cases.
However, there is absolutely no point in remembering enough detail to be able to code production quality implementations of these algorithms on the first try off the top of your head. This is what libraries are for. For example, if all you remember is the canonical 3-line version of the quick sort and you can't remember how to implement one that doesn't easily find the O(N^2) cases and sorts in place, there's nothing wrong with that.
No, that is what the Internet is for. I'd rather demand page that kind of knowledge in, rather than have it take up space for something more useful.
I think that it is worthwhile remembering the concepts behind important algorithms and data structures. But for the implementation side, I would argue to use a library function if at all possible. It is easy to forget about borderline cases when you write down the algorithm - and it is quite probable that you don't think of them if you do a unit test. As a result, even such simple algorithms as binary search are likely to be broken:
From the Google Research blog. The rest of the text is a recommendation worth as well, but it's not about memorizing algorithms.
Its always better to find ways to understand the underlying principle of such algorithms rather than memorizing them. For example - Quick Sort uses Divide and Conquer paradigm (it is a design technique to solve a certain class of problems).
Wiki is a very good starting point to dissect a new topic. You can dig deep by watching video lectures (found this good post on Video Lectures here on SO) and other specific material such as concerned research papers.
Working out examples will also clarify the algorithm better.
I hope this helps.
cheers