3 points · by resdirector · 13y ago · 9 comments
I've just spent the last twenty five minutes studying data structures and algorithms and I'm bored out of my mind.
Can anyone suggest any materials that bring to light the inner beauty of data structures and algorithms (over and above explaining the theory)?
In general, I find the best way to study these sorts of things is to have a puzzle to solve, to work through it, and then have a mentor demonstrate a little piece of magic that makes me feel stupid for not having thought of it. Here's an example that you may not know, but most people here will.
In the Pollard Rho method of factoring you compute f(x) repeatedly, and need to find somewhere that it repeats. So you start with x[0] = x0, then compute x[n+1]=f(x[n]). Question - find i and j such that x[i]=x[j].
You can think of this as an implicit linked list between integers, and you're given a starting point and asked to find a loop. How can you do this with fixed, limited additional storage?
Yes, there is an algorithm to do that.
Here's another. Suppose you have a vector of key/value pairs and you need to sort on the key. More, if two keys are equal, their positions in the result must be the same as their positions in the original. Can you do that? Many library sorts don't offer that option - can you find a way?
Having found some of these sorts of problems in the real world and puzzled over them, only to find that (a) they've been done, (b) they've been done better than you thought possible, and (c) there is a touch of magic about the answer, then you might become more engaged with the topic.
Otherwise, maybe the job isn't really for you.
Especially:
> In general, I find the best way to study these sorts of things is to have a puzzle to solve, to work through it, and then have a mentor demonstrate a little piece of magic that makes me feel stupid for not having thought of it
(Actually, I could quote your entire comment, thanks, very much appreciated!)
What's even better is the repeat - where you smile and realise there is no head banging needed :-)
The book teaches concepts of Algorithm and Data Structure in the context of Complex System Sciences.
Though it's a bit light-weight, but it might be a good starting point.
[edit: not particularly helpful, sorry!]