Ask HN: How to learn algorithms and become a good programmer?
Hi HN'ers,
I am from a non-CS background. I find myself able to make stuff work and resolve issues in case any pop up, but i do not find myself writing the most optimized code.
How do i learn algorithms ? The problem is that the suggestions posted in various posts in HN are pretty intimidating to start. Is there a beginner friendly book or a youtube lecture that de-mystifies and simplifies learning algorithms ?
I mailed a few people whom i admire if they could provide guidance and / or mentor me, but haven't found help. IRC channels are intimidating too.
I would be grateful to the community for any help.
18 comments
[ 3.2 ms ] story [ 55.4 ms ] threadMIT OCW's Intro to Computer Science and Programming (in Python) covers a lot of ground related to programming (more than just Algos), but it covers some essential sorting algorithms and eventually gets into dynamic programming. I don't think anything much simpler than this would be worth your time (not to say this is the best), but the readings themselves (especially those from wikipedia) can actually be a little dense: http://ocw.mit.edu/courses/electrical-engineering-and-comput...
MIT OCW also has a full course on algorithms.
it may work to start with just one area, an area that is close to something you already are making or solving, and then, literally, in searching for algorithms for that pick the shortest one and solve a small implementation of it.
in finding a reference implementation i found the following helpful :
-- pick code in the same language you will be writing your version in.
-- if you can, find and read the original paper ( try searching google scholar ) describing the algorithm, these are often clearly written and explain the motivating situations that led to the way the algorithm was constructed.
finally some example short algorithms from a few areas and favorites of mine :
string processing :
-- LZW algorithm
-- longest common subsequence algorithm
tree graph processing :
-- post order depth first search
list processing :
-- group elements in an array into sub arrays of length k
integer processing :
-- change of radix algorithm ( change a mumber from the given base ( 10 ) to base 2 ( or even to other bases as well ) )
most of all, just work your way through step by step, like the algorithms your are making.
The thing is is that merge-sort was discovered by John von Neumann [1] and QuickSort by CAR Hoare [2]. The less accomplished of the two won a Turing Award and one might quite legitimately walk away with the belief that developing algorithms from scratch may be non-trivial simply because the subject is really hard.
Which is a round about way of coming to some advice: if the very subject of algorithms isn't enough to scare you off, don't fret the fact that the presentation looks difficult. The apparent difficulty is in the subject itself and the only thing a gentle introduction or simplification means is that someone is pretending that the subject of algorithms is not really really hard with the natural consequence that when it does get hard, you're more likely to see the struggle as a failing of the student rather as inherent in the subject matter. And everything interesting and important in algorithms is hard.
This is why I don't hesitate to suggest people consider TAoCP. It covers the "easy" parts as well as or better than anything else I've seen. It just requires being ok with not understanding everything or even most things that Knuth covers because he finds them important and interesting. Because I'm never going to be that smart, I might as well work at my own pace, and celebrate the small victories like grasping the answer to one of the easy exercises that a year ago, I wouldn't have grasped.
The other recommendation is to take an algorithms course on Coursera. It's free.
Good luck.
[1]: https://en.wikipedia.org/wiki/John_von_Neumann
[2]: https://en.wikipedia.org/wiki/Tony_Hoare
The above books are quite apt for beginners. You should expect to struggle a little but you must persevere anyway. I remember struggling with sorting and matrix multiplication algorithms when I learned it the first time in school. Do not mistake your unfamiliarity with the subject for its inherent difficulty! Once you write a few sample programs and see how the algorithms play out, you'll get the hang of it.
https://projecteuler.net
Remember that "making stuff work", aka prototyping, is incredibly important, and in fact an extremely desirable skill: in so many situations, it can be impossible to see the forest for the trees when building a new idea or architecture, and the design is still on paper; things frequently need to be built out into working first drafts for edge cases or gotchas to become apparent. Often, the result is that everyone might need to go back to the drawing board and start from scratch, so rapid turnaround is essential.
Going beyond the basics in any domain is a categorical form of specialization, and specialization in any context tends to require a lot of investment, and the return it gives predominantly leans toward inflexibility and a narrow field of application.
When tackling arbitrary, ambiguous problems, the statistical likelihood your specialized knowledge will come in handy is, on average, going to be quite low, unless you're in an academic environment that focuses on your specialty.
So don't shun the skillset you already have in "making things work." :D
By all means dive into algorithms - just remember the info will likely stay in if you do so at a slow, non-anxious pace and keep your experiences positive ^^