Replies To: Learning Algorithms

Re: Learning Algorithms

Posted 20 February 2013 - 01:40 PM

Algorithms are language agnostic. If you want implementation practice, use whichever language you feel most comfortable with. At it's core, an algorithm is just a finite sequence of steps that produces a specific result. So question 1 is basically asking the same thing twice.

As a computer scientist and software engineer, you should be comfortable implementing algorithms from clear descriptions and pseudo-code, as well as problem solving yourself.

I feel like my answer might be a little vague and abstract, but I'm not exactly sure where you're going here. I'll be happy to clarify or expand on something if you want me to.

Re: Learning Algorithms

Posted 20 February 2013 - 02:03 PM

I would tend to say that Java or C are good choices for studying algorithms, simply because they leave more room for you to work. In python, it's harder to get down to the basics, since the language really doesn't want you to think at low levels. This makes it a great programming language but not a great learning language.
Also, the classic college-level text on algorithms, Sedgewick's, is available in editions that target C and Java, so those languages have an advantage there. (Though I admit I prefer the C edition - the most recent edition is far more noisy than it needs to be)

That being said, the truths of algorithms are mathematical ones, not language-specific ones, so any language will do. If you write a quicksort correctly, it'll outperform an insertion sort no matter what language you write it in or what machine you run it on - that's the argument for studying algorithms generally and not "algorithms in C" or "algorithms in lisp".

tlhIn`toq, on 20 February 2013 - 03:44 PM, said:

It may not be the same in all programming areas, but there aren't really that many 'algorythms' to learn in my area. The workflow is odd and I have to work out my own logic for getting the job done.

I have to say, I'm spending a lot of time these days cleaning up after a guy who has no conception of algorithmic complexity. Flattening out loops and loops and loops, trying to get responsiveness closer to a reasonable level. It's definitely a good idea to spend a semester or two thinking about what computers spend their time on.

Re: Learning Algorithms

Posted 20 February 2013 - 06:43 PM

jon.kiparsky, on 20 February 2013 - 02:03 PM, said:

I have to say, I'm spending a lot of time these days cleaning up after a guy who has no conception of algorithmic complexity. Flattening out loops and loops and loops, trying to get responsiveness closer to a reasonable level. It's definitely a good idea to spend a semester or two thinking about what computers spend their time on.

This.

I've had to deal with really terrible code before, and when I see two nested for loops when its not necessary I just cringe...

Re: Learning Algorithms

For example, do you learn the whole "Introduction to Algorithms" book by heart or do you read it and know where to look when you need something ?

So it's more a question of Know vs Know where to look .

And I recently looked into Python and I was wondering if it's worthed to learn it (that's where my second question came from )

I'm sure some people do that. Most people just learn a few tricks to be able to accomplish most practical goals such as telling the order of an algorithm. The kinds of people who have an entire algorithm book memorized are the kind of people who are very fascinated with mathematics. Just as a hunch, I would say most people get a general feel and then look stuff up when they need to, but this is just my experience. Hopefully that answered your question

Re: Learning Algorithms

Posted 20 February 2013 - 10:44 PM

I think it's a lot less useful to memorize algorithms than to learn how to reason about algorithms. If you understand running times and big-O notation, you're in good shape. In order to learn this, you're probably going to get familiar with a few algorithms, and there's certainly no harm in picking up a copy of The Art of Computer Programming and just working through the material there, but that is not necessary to be a good programmer. As NecroWinter says, that's mostly something you'll do if you really get into the math of it. The math is worth getting into, especially if you want to understand topics like cryptography, but to be a good programmer you really want to have a good set of intuitions about algorithms and how they work, not a headful of Floyd-Warshall and Graham Scan and whatnot.

(thinking about it, I have to say - if you want to be a better programmer than you are, of course, going through a copy of Sedgewick's Algorithms in C and working each and every one of the problems in it is not at all a bad idea. Even if you don't remember exactly how to implement a red-black tree, you'll have worked your brain on some really good hard problems)

Re: Learning Algorithms

Posted 20 February 2013 - 10:58 PM

I'm not the guy to tell you exactly what math you should prepare yourself with, but if you can work through the basics of discrete math and number theory you'll probably do yourself no harm at all. The guy to listen to on this is macosxnerd101 - he's got a lot more formal math training than I do. (which is to say, >0)

Re: Learning Algorithms

Posted 21 February 2013 - 02:04 AM

Quote

1.Do you learn some new algorithms from time to time or do you look for something that fits for your new task and learn them when you need them ?

Both. I'm always looking out for new things to learn and am slowly making my way through Skienna's The Algorithm Design Manual. But my area of work often benefits from off-the-shelf algorithms (maybe slightly modified) that are more efficient than anything I would come up with myself. In these cases, I look them up as needed (often in Skienna).

Quote

2.If you want to learn and get used to some algorithms , would you rather use languages such as C/C++ or higher level ones like Python ?

I'd rather use a language I was already familiar with. It will let me concentrate on the details of the algorithms in question without getting distracted by details of unfamiliar syntax.

Re: Learning Algorithms

I'm a highschool student at the moment . Going to university next year ... and I always like to be one year ahead at least ... />

Thanks for all your help !

I got a few PM's about a year ago asking how to get started with data structures and algorithms. If you're in high school, you might want to start with the topics outlined here, which are standard Data Structures I topics. The algorithms books suggested are more typical of a 3000 Data Structures II class or a 4000 Algorithm Analysis class. Those are good to know, but those come after you have the basics down. And really, you want a certain familiarity with proof writing, beyond what you get in high school Geometry.

jon.kiparsky, on 21 February 2013 - 12:58 AM, said:

I'm not the guy to tell you exactly what math you should prepare yourself with, but if you can work through the basics of discrete math and number theory you'll probably do yourself no harm at all. The guy to listen to on this is macosxnerd101 - he's got a lot more formal math training than I do. (which is to say, >0)

At the high school level, Calc I-II and Statistics are really good preparation for college. Having Discrete Math and Number Theory under your belt are a plus. Some discrete classes omit Combinatorics and Graph Theory as well. Those are very important topics for any computer scientist. You'll pick up enough Set Theory along the way. And if you haven't already, brush up on your formal logic, and perhaps Boolean algebra proofs (ie., proving a number system is a Boolean algebra). I want to emphasize proof-writing again. You should be familiar with proof by induction and proof by contradiction, in addition to direct proof. Proof by contrapositive is nice to have as well, but not nearly as important as induction and proof by contradiction.

Re: Learning Algorithms

Posted 21 February 2013 - 08:47 AM

Quote

You should be familiar with proof by induction and proof by contradiction, in addition to direct proof. Proof by contrapositive is nice to have as well, but not nearly as important as induction and proof by contradiction.

Good call. Proof by induction might be the hardest to get your head around*, and it's very important, particularly for recursive algorithms. If you make a particular effort to have this in your bag, you might find this smooths your path.

*At least, it seemed weird and magical to me the first few times I encountered.