Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Possible Duplicate:
How important is studying algorithms and theory is to becoming a great programmer?

Today I learned the fast sort Algorithm. I doubt I will ever implement my own version though as C# has its own built in Sort method for lists and arrays.

How important is learning Algorithms for high level language programmers? In my example I gained no benifit from knowing the Algorithm but perhaps my example was too trivial to be accurate?

share|improve this question

marked as duplicate by Péter Török, kevin cline, Yannis Rizos, Corbin March, ChrisF Dec 2 '11 at 13:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5  
Do you expect that the vendor will always provide everything you will ever need? –  user1249 Dec 1 '11 at 11:40
3  
How important is doing something interesting/challenging in your career? Also, did you learn when NOT to use the built in sort? Quicksort is terrible when the data is almost sorted already which is why it is important to know other sorts/algorithms... –  Jetti Dec 1 '11 at 13:48
    
Ironically, that is almost the exact reverse of Is it reasonable to expect knowing the whole stack bottom up? –  Vaibhav Garg Dec 1 '11 at 17:06
1  
@Péter, I think the focus on high-level programming could make this enough of a distinction from your duplicate, if the answers would focus more on that aspect. –  Karl Bielefeldt Dec 1 '11 at 17:14

12 Answers 12

up vote 8 down vote accepted

Which sort algorithm did you learn? Quicksort, heapsort, bucket sort, insertion sort, radix sort, bubble sort, or a bunch of possible others? Which sorting algorithm does C# use?

What I'm getting at is that there are many possible strategies for many algorithms and data structures (containers are another good example) that each have their own benefits and drawbacks. Any single "generic" implementation will have made a specific choice regarding those benefits and drawbacks - and that choice may not be optimal for your particular problem.

Now, that may not be an issue, as you don't want to prematurely optimize anyway, but being unaware of these choices, drawbacks and benefits leaves you a gaping blind spot in your well-roundedness as a developer.

share|improve this answer

You know you will not always write trivial code, at some point in your projects you will have to write an algorithm that solves a hard problem for example matching objects with each other according to some data. And when you do that, you will have in mind the complexity of an algorithm so the solution you come up with will have a perspective of an algorithm designer in it.

share|improve this answer
17  
+1 you will have in mind the complexity of an algorithm so the solution you come up with will have a perspective of an algorithm designer in it Brilliant. Learning algorithms is learning the algorithmic process and perspective, not so much the algorithms themselves. –  Yannis Rizos Dec 1 '11 at 9:29
    
In that case I would just use another C# feature like lambda functions –  Tom Squires Dec 1 '11 at 9:36
8  
@TomSquires - language features are completely orthogonal to algorithms. If you know an algorithm you can usually implement it in any turing-complete programming language. In other words that knowledge applies to programming in the general, not specific to one language or implementation. Now, lambdas are actually a generic mathematical concept themselves, not just a language feature, but that's another can of worms :). –  Joris Timmermans Dec 1 '11 at 9:43
4  
@TomSquires -- I'm not sure if you're joking or not. –  user39685 Dec 1 '11 at 13:25
1  
@TomSquires - also you're assuming you're working in .NET. Technologies change. Jobs change. –  GrandmasterB Dec 1 '11 at 18:42

I doubt I will ever implement my own version though as C# has its own built in Sort method for lists and arrays.

Let's say you need a fast median algorithm. Few standard libraries I'm aware of have such a thing built-in. But if you know how quicksort works, it's very simple to modify it to get an algorithm for finding the median in O(n) time. My point is: Algorithms&data structures often have to be modified for a specific problem, and to be able to do that, you need to know and understand them.

share|improve this answer

I think you should not be misled by the fact that you want to program in a high-level language. A high-level language gives you lots of abstractions (data types, control structures, memory management, standard libraries, etc) that make certain tasks easier for you.

As a result, a task that once seemed very complex (e.g. sending an email through smtp) can now be achieved by performing a few calls to some library functions. What is the consequence of this? That it is possible to construct applications that are much more complex than before.

So, at the end of the day you will still have to do with very complex software projects because high level languages have only taken the complexity of software to a different level. What I mean is that, say, implementing a business application in C#, Java or Scala can be as complex as (or even more complex than) implementing a device driver in C / assembly.

So, IMO, high-level programming languages will not protect you from having to deal with real algorithmic or architectural problems: they have made specific programming tasks easier, but they haven't made programming less difficult or challenging in general.

share|improve this answer
    
Very nice answer. –  Peter17 Dec 2 '11 at 11:19

You would not use a C# built in Sort method (or anything else for that matter) without knowing what it does and how it goes about doing it, in all its detail -- that is just not being a programmer. You could be an excellent coding help to a programmer, though.

share|improve this answer
4  
I disagree: you can and will use lots of built-in functions without necessarily understanding their inner workings; just knowing their contracts and high level properties is enough. However, that does not mean that you shouldn't know any algorithms as a general principle, because it's very likely there will be situations where you need to understand, tweak or compare algorithms. Or, god forbid, provide your own implementations! –  Andres F. Dec 1 '11 at 13:17
    
This is a no true scotsman argument. Why is it "just not being a programmer"? –  Karl Bielefeldt Dec 1 '11 at 17:10
    
@KarlBielefeldt Let me first checkout "no true scotsman" :) –  Kris Dec 2 '11 at 4:15
    
Oh yes, but this is certainly not an argument without substance. –  Kris Dec 2 '11 at 4:17

Algorithm knowledge is absolutely essential for programmers for the following reasons:

  1. Programming is everything about handling large amounts of details. Details that are all linked together to a consistent system. Algorithms are just well known patterns of details, where solutions are known. 99% of the cases the details are not structured like those well known patterns expect, and the algorithms need to be customised to the particular situation -- it's just not possible to write any significant software without algorithm knowledge.
  2. Data structures are another aspect of the same problem. Computer memory storage lets us store information. But deciding correct representation in the computer memory for that information in every state during the algorithm execution is significant problem in itself. If there are problems with learning algorithms, then learning data structures is simpler way to learn the same thing.
  3. In the end, it's all about bits in the computer memory. It's either 0 or 1. There are sequences of bits like 010, and then those are then boxed inside data types. During the lifetime of the data, the value of the bits will change, and the system moves from one state to another repeatedly, and finally a normal form - the result of the program is reached, and execution stops until it is again activated by an external event.
  4. These execution sequences in the program from activation of the execution to the normal form can become very complex. Handling this complexity together with data changes is what algorithms are all about.
share|improve this answer

Learning algorithms (and, last but not least, data structures) is most important. Even if you should of course use the sort function of your language's library, you then know that sorting is comparatively not a cheap operation, hence you will write your code so that sorting is done in the right moment.

share|improve this answer

You don't have to know much about how a car functions to drive it but you'll almost certainly, at best, only be a relatively average driver. The more you know about cars the better driver you can be. To be an elite driver, you will know as much as possible about every detail of your car, its engine, even your physiology and the ergo-dynamics of the cockpit. It then doesn't much matter what car you drive, you'll be able to quickly assess its capabilities and drive it effectively.

Or, simply, as with anything, the more you know, the better at that profession you will be.

share|improve this answer
1  
I didn't downvote, but the analogy seems flawed: Wouldn't the car driver be computer program user? Could you be a good "vehicle developer" without knowing how a car's components work? –  nikie Dec 1 '11 at 17:39
1  
@nikie Reread by replacing "driver" with "programmer" and replacing "car" with "algorithm" or "program". –  nicerobot Dec 1 '11 at 19:03
1  
@YannisRizos where is my analogy considered a proof? It's simply an example of my belief about the study of algorithms. You don't have to agree but it isn't a proof of anything so it isn't a logical fallacy. –  nicerobot Dec 1 '11 at 19:05
1  
@YannisRizos o_O Huh? "How important is learning Algorithms for high level language programmers" By it's very nature, that question is subjective which implies it can't be proven and that all "answers" will be the authors' opinion and hence, essentially a discussion board. Wow! You just want to disagree with me. That's fine! Have fun with that. –  nicerobot Dec 1 '11 at 19:31
1  
@nikie Can you use sort without knowing how sort works internally? Which sorting algorithm it uses? Of course you can! And that was Tom's question! –  nicerobot Dec 1 '11 at 19:33

Every program is an algorithm. Learning algorithms is about learning the more generic patterns, and the concepts involved. I never need a sort algorithm by itself, but I need a sort plus a tree plus a unique set of steps to solve a problem. I end up with an algorithm that is unique to this problem.

If I don't know about designing algorithms, how will I solve my problem? You probably won't write a new sort, but the classic quote "Data structures + algorithms = program" is true for every program. You have to know which algorithm to use where, and how to build your own.

I leave aside completely the fact that algorithms are useless in a data vacuum.

share|improve this answer

There are dozens of questions on Programmers.SE of the form "Do I need to know X to be a successful programmer?". Programming is a huge arena with thousands of different kinds of jobs, so no matter what 'X' is, the answer is 'No', because you can find some subset of programming jobs that doesn't need 'X'.

Unfortunately, what usually goes unsaid is that each time you decide to 'just get by' and blowing off some subject, you are implicitly making choices about the sorts of programming jobs you are going to take in the future. None of us can know everything, so these choices have to be made, but they should be made with some thought for the future of your career, not just to avoid some current inconvenience or effort.

Yes, there are lots of programming jobs where a formal knowledge of algorithms would go to waste. The question is: Are those the sorts of jobs you want to be working at ten years from now? If not, you should now begin laying the groundwork to qualify for other jobs in the future.

share|improve this answer

Built-in language features and library functions, like the sort function are abstractions. And when one of those abstractions leaks, as they invariably do, you will not know what hit you, if you don't understand complexity of algorithms.

share|improve this answer

I do not think that for a high level language programmer learning algorithms is important for being productive. It is like knowledge about how the compiler works, how the garbage collector works, how a finite state machine works, why floating point operations can lead to wrong calculation results, how ASCII is different from UTF-8 and so on and so on.

High level languages, which deliberately hide such low level stuff from the programmer, want to give you the possibility to concentrate on business rules. I have seen many programmers lacking of "low level" knowledge and still get their work right.

Like a mechanic can get the most out of his car than an ordinary car driver, a programmer with (at least some) "low level" knowledge will make better decisions. For sorting algorithms this means for example: If you know that that the data is partly sorted then you will likely choose Bubble sort. The programmer guy next to you, who does not know this, might choose a slower algorithm. Will he get his work done: Yes. Will he be able to explain the stakeholders if he can make the sorting faster? Maybe not.

However: Does it matter? For most applications which are programmed with a high level programming language, it rarely matters. But in those rare cases, wrong decisions can have devastating consequences. The wrong sorting algorithm will make your program slow, the wrong decision over the character encoding will make in internationalization impossible, and the wrong number type lead to wrong calculation results.

So it is up to you: Do you want to be productive or do you also want to make the right decisions?

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.