

Ask HN: Is learning algorithms and datastructures really important? - stormrider

Yes I know this is a dumb question, hear me out.<p>(I am a regular here on HN, using an alternate id to avoid my history "polluting" this post.)  A student going through her Bachelors in Comp Sci asked me a simple question which staggered me a bit and I wasn't able to give a coherent answer, which disturbs me a little. This was the question<p>" Why do I <i>really</i> have to learn algorithms and datastructures, (beyond the basics) Most (almost every? ) professional programmer's work involves gluing libraries together and/or debugging or maintaining existing codebases. Granted, it <i>is</i> important to have an <i>overview</i> of the important data structures and algorithms and understand the O notation and so on, but the impression I have is that a <i>deep</i> knowledge of algorithms is not important to the vast majority of programming work or to be a goood programmer or Open SOurce contributor. Is my impression correct?"<p>What do HN ers think? Do you have to use formal algorithmic analysis in your work? What kind of project would demand deep knowledge of algorithms?<p>What would be a good Open Source project where an algorithms expert would be able to add significant his expertise (assuming he is a good programmer/ debugger etc)? (This was a followup question).<p>I always <i>assumed</i> that deep algorithmic knowledge would be a great skill to have, and now I can't justify that assumption to my satsifaction! It freaked me out a bit and I thought I'd tap HN.<p>How should I answer this young student? Help!
(Assuming this submission get some traction, I'll ask her to read the comments on this.)<p>Any comments greatly appreciated. Thanks in advance.
======
cperciva
Learning algorithms and data structures is important because:

1\. Knowing the standard algorithms and data structures will allow you to
figure out which one you should be using, even if you're just doing that via
an external library.

2\. Knowing the standard algorithms and data structures will help you in cases
where you want something which is almost but not quite standard. For example,
I recently wrote a no-inserts hash table, because for my particular
application I wanted to start with a populated table and then gradually remove
entries; by removing the ability to insert entries, I made the code much
simpler and faster (no need for rehashing!) -- but if I hadn't been entirely
familiar with standard hash tables, I wouldn't have been able to do this.

3\. Studying the standard algorithms and data structures gives you an
opportunity to learn how to think about algorithms and data structures. Even
if you live your life without ever needing to sort a list, having studied
sorting algorithms will make it easier for you to figure out the best way to
solve whatever obscure domain-specific problems you do encounter.

~~~
plinkplonk
"For example, I recently wrote a no-inserts hash table, because for my
particular application I wanted to start with a populated table and then
gradually remove entries; by removing the ability to insert entries, I made
the code much simpler and faster (no need for rehashing!) -- but if I hadn't
been entirely familiar with standard hash tables, I wouldn't have been able to
do this."

The great thing about this answer is that it gives a _specific_ example _from
personal experience_ \- which the submission explicitly asked for (vs
platitudes about how acquiring algorithmic knowledge is "cool" in general,
with references to code monkeys/CRUD/dumb managers and so on).

Everyone agrees deep algorithmic knowledge is a good thing to have _in
general_. Specific, practical examples, based on personal work or experience
are hard to find - Skiena's book on algorithms gives some examples. He calls
them "war stories".

I suspect that the student is right in that _most_ programmers never use the
algorithmic theory they learn and most jobs are the "stitch together api s"
type. But if she is building something like etherpad for example, she would
need seep algorithmic knowledge - essentially when a programmer "goes where no
one has gone before" and builds something truly innovative.

~~~
plinkplonk
I'd really like to hear any answers to "Are there Open Source projects which
demand a high level of algorithmic knowledge?" I suspect (but don't know for
sure) that the linux/bsd etc kernels and networking code would be full of neat
algorithm/data structure tricks.

Maybe a shortcut to find such projects or applications would be to look for
projects where high performance is a _critical_ (vs nice to have) property of
the program.

~~~
cperciva
_I'd really like to hear any answers to "Are there Open Source projects which
demand a high level of algorithmic knowledge?"_

I know at a minimum that the FreeBSD kernel uses sophisticated algorithms for
keeping track of virtual memory, TCP connections, and internet protocol
routing, because I've seen CVS/SVN commits related to those. Beyond that, I
can't really say -- I know algorithms, but I don't know kernel.

------
Xichekolas
If she wants to sit in a cubicle churning out CRUD apps for businesses, then
yeah, _deep_ understanding of algorithms and data structures will rarely be
called for.

If she wants to work on anything cool (the kind of problem that keeps you up
at night), she almost certainly will run into a situation that involves
knowing this stuff. I'm not just thinking of the usual definitions of 'cool'
problems (compilers, etc). There are lots of problems that aren't as _meta_ as
a compiler that are also hard (and hence cool)... routing delivery vehicles,
or optimizing any number of metrics.

Without a good grasp of what is out there, you'll be forced to do one of two
things. Either you'll spend a lot more time than necessary to reinvent the
wheel, or you'll implement the most straightforward solution, which might be
far from optimal in both time and space. There is always the outside chance
that you'll come up with something new and better than anything that already
exists, but I'd argue the chances of that are much better if you already
understand what is out there.

So yeah, I rarely need to do analysis for my day job, but am knee deep in
combinatorial optimization algorithms for a side project.

For the followup question: any project that implements a language or a library
is a place that good algorithms/data structures can make a tremendous
difference. But there are applications everywhere. Even boring things like
looking up a name in a phone book can benefit from knowing what a Trie is.

------
cullenking
It is important if you ever plan on writing software that works well. For
example, I am working on an application that draws routes on Google Maps.
There are points that comprise the route, and the points have data associated
with them. I wanted to be able to mouse over the map and have the nearest
point on the route highlighted and populate a headsup display with the
information it contained. This is a non-trivial problem to solve efficiently.
You can do it the naive way and just linearly search all the points on the
route on every mousemove event, however, that can be hundreds of thousands of
comparisons a second for a long route. However, if you use an efficient data
structure for multi-dimensional searching, like a k-d tree, you can find the
point in 20 or so comparisons for a large route.

The best part is that data structures like a k-d tree are rarely covered in
higher ed CS programs. However, if you have a core competency with algorithms
and data structures, finding the appropriate data structure or algorithm and
implementing it becomes so much easier.

Even the simplest data structures to implement, like a linked list, come in
handy. In the same application, I had need for a linked list structure however
flash has none. However it was trivial to cook up (after all the work on the
k-d tree), and 30 minutes later I was in business.

stevecooperorg said it best: if you want to just glue crap together, then
probably not. However, even "gluing things together" can be assisted by these
concepts! My mapping application could be considered "gluing", however to do a
novel job and make it more than the competition, you have to have the extra
bit of knowledge.

------
keefe
If she is looking to be mediocre and use writing software as a ramp into being
a nearly-technically-competent manager, then no, algorithms and data
structures are not important. If she wants to have any deep understanding of
this field? Well, 90% of it is data structures and algorithms. If you are so
adverse to taking such classes, maybe IT vs CS is the path.

------
stevecooperorg
She's right that if all you need to do is glue stuff together, then she
doesn't need to study it. Trivial problems are trivially solved. By very low-
paid people. Who are very bored.

But what I've noticed is that there are only so many non-trivial problems, and
the formal pieces are the little pieces of distilled wisdom, the 'lego bricks'
from which you build anything beyond trivial software. You might find studying
graph analysis algorithms, say, to seem utterly academic, but there will be a
time when what you're asked to do is to analyse a graph, and you'll be glad
that your 'mental index' includes that entry.

I suppose the thing is this; if you've studied enough that ten years down the
line, someone can ask you to solve a problem and you can say 'ah, yes, this
requires an FSA' or 'I can do it with A*' or 'that's easy with a red-black
tree', then you know enough.

------
yannis
One of the most obvious answers is that the most well known and most
successful web businesses have actually based their business on algorithms.
For example Google and Wolfram.

Although one does not have to be an Architect to build a house, you will need
to be one to build a 50 story high building. The question is common in many
disciplines and can be translated as ... why do I need to learn that, if I
will not be using it at my future workplace... However, from my own experience
as an Engineer (Mechanical) a true professional must have the breadth as well
as the depth of his field.

Since any program is an algorithm the more you understand algorithms the
better.

Program= Algo(Algo1+Algo2+Algo(Algo+Algo..)....)

~~~
notaddicted
Actually the house is seen as all architecture, the architect is relatively
free from engineering concerns (bridge, all engineering.)

I agree though, to do something new, or to implement new ideas that have not
been libraryized you need to understand the algorithms and be able to
implement them.

Is it necessary? You can earn a salary without it. You can also earn a salary
selling houses, it doesn't matter, it depends what you want to do. You need
what you want.

------
yan
Understand algorithms, data structures, and "theoretical" topics adds tools to
your toolbox. If you are working on anything interesting, chances are you will
end up re-inventing half a dozen wheels, taking much longer and coming up with
a far less elegant and workable solution. The reason complicated topics exist
is because they helped earlier solve problems that weren't obvious, and those
problems are the ones worth solving.

I guess what I'm trying to say is, yes, you can write code knowing only the
basics, and yes you can cobble something together, but you'll always be
limited by yourself.

Not to mention, learning more theory can help open your mind to other
_categories_ of solutions and more ways to approach problems

------
stormrider
"Knowing the standard algorithms and data structures will help you in cases
where you want something which is almost but not quite standard. For example,
I recently wrote a no-inserts hash table, because for my particular
application I wanted to start with a populated table and then gradually remove
entries; by removing the ability to insert entries, I made the code much
simpler and faster (no need for rehashing!) -- but if I hadn't been entirely
familiar with standard hash tables, I wouldn't have been able to do this."

That is a _great_ example (and answer!) thanks!

------
jonjacky
In their book The Practice of Programming, Kernighan and Pike explain the
really important stuff in about 30 pages, chapter 2 in the book. They cover
four data structures: array, list, tree and hash table, and two kinds of
algorithms: sorting and searching. They say that just these are enough for
most common situations.

