3

I'm a student of computer science trying to soak up as much information on the topic as I can during my free time. I keep returning to algorithms time and again in various formats (online course, book, web tutorial), but the concept fails to sustain my attention. I just don't understand: why are algorithms so special?

I can tell you why fractals are awesome, why the golden ratio is awesome, why origami is awesome and scientific applications of all the above. Heck I even love Newton's laws and conical sections. But when it comes to algorithms, I'm just not astounded. They are not insightful in new ways about human cognition at all. I was expecting algorithms to be shattering preconceptions and mind-altering, but time and time again they fail miserably. Perhaps I am doing something wrong in my approach.

Can someone tell me why algorithms are so important to programming?

14
  • 21
    They are not insightful in new ways about human cognition at all. Algorithms are not about human cognition but machine cognition, so that we can get results from machines as fast as possible. Sep 1, 2012 at 5:11
  • 7
    Perhaps you should consider switching to Psychology? It sounds like you're much more interested in that topic..
    – Izkata
    Sep 1, 2012 at 5:29
  • 5
    Read amazon.com/G%C3%B6del-Escher-Bach-Eternal-Golden/dp/0465026567/…. Maybe you'll understand. Sep 1, 2012 at 5:45
  • 3
    That said, some algorithms are awesome even when used by humans. Take binary search for example - it speeds up searching through catalogues, book indexes, and the like, immensely!
    – mikołak
    Sep 1, 2012 at 9:26
  • 5
    Fractals are generated from really simple algorithms (that's part of why they're awesome). The golden ratio can be described by a really simple algorithms (which is why it turns up in nature). Origami is the application of folding algorithms to paper.
    – OrangeDog
    Sep 1, 2012 at 14:05

11 Answers 11

24

Algorithms are a very central part of any kind of computation or computer program. In fact, computer programs are only a bunch of algorithms slapped together with some fancy structured data. That's it. Algorithms + Data Structures = Programs.

A computer program consists of logical rules which it follows. Such rules are structured as algorithms. Rules alone are useless, as they do not operate on anything - they lack substance for which they are meaningful. Just like it is meaningless to try to spoon food from an empty plate - without food the process yields nothing. It's useless. But when you add that substance, in this context food or data it all becomes meaningful. There's something to operate on.

Algorithms then define how to operate. What exactly to do to solve a problem. Different kinds of algorithms solve different kinds of problems, it is important to understand how the algorithm solves the problem, because without understanding of what one's doing it's impossible to see things from higher perspective. Similarly, one can't build a bridge by just placing brick after another. There has to be deeper understanding of what exactly one is doing, what problem they are solving and why they do it the way they do. In context of computing and computer programming, understanding and studying of algorithms give this understanding.

2
  • Just take a good long look at how Quantization and Huffman Coding are used for lossless compression in the MP3 and JPEG formats. I mean, really understand it. Then imagine that the majority of electronic devices sold today provide hardware implementations of either or both. Physics is amazing because it involves understanding the underlying mechanisms of nature, algorithms is the same but the mechanisms are all man-made. Algorithms are the meta-language of machine consciousness. Jan 25, 2013 at 23:48
  • This doesn't answer the question. Admittedly, it's a poor, off-topic question, but this isn't the answer :)
    – Andres F.
    Jan 28, 2013 at 20:46
14

They are not awesome. It's just an ordinary tool we use in development like any other tools.

Its sole purpose is to provide an answer to a specific problem, avoiding reinventing the wheel again and again, i.e. wasting your time.

Examples:

  • If you need to sort a list, you would use an existent algorithm, instead of wasting your time inventing your own.

    Exception: you know exactly what are you doing and you know that in a particular situation, yours will be faster or somehow better compared to any other.

  • If you need to hash a password, you would use an existent algorithm, instead of inventing your own, and not only wasting your time, but also introducing a security threat.

    Exception: you are a security researcher and have a lab of experts ready to test your new algorithm.

3
  • 2
    I disagree with your first statement. I find there are some very awesome algorithms. For example, many hashing algorithms are just algorithms, but the ones that multiply by 31 to take advantage of the "bitshift and subtract" optimization, while still keeping a prime multiplier, I think those are awesome! I'm entirely fascinated by the brilliance that people are able to apply to our craft, in the same way that basketball players marvel at their superstars and the awesome moves they make.
    – corsiKa
    Sep 1, 2012 at 15:24
  • @corsiKa: What I wanted to say is that they don't have to be awesome, to answer to the original question: "Can someone tell me why algorithms are so awesome?" Sep 1, 2012 at 19:50
  • While applying existing algorithms is well and good, practicing the art of understanding and developing new and novel algorithms is not only challenging but requires a high degree of creative (ie divergent) thinking ability. As opposed to memorizing (ie convergent) existing implementations. Not everybody is satisfied with mindless assembly. Algorithms are the soul of programming. Jan 25, 2013 at 23:37
9

What do you mean "not awesome"?

How did your first sorting function look like? Did it take N log(N) time to sort the array? Or was it a variation of insertion/selection/bubble sort?

Would Internet search engines be possible without algorithms? Would people use Google as often as they do if it took as little as 2 minutes to search through 20 billion of pages they index? Try to create an application which will allow your to text-search a folder with a mere 1GB of text files and see how that goes without algorithms.

I find looking for ways to decrease the running time of a piece of code totally awesome. You are provided knowledge others studied for decades and able to grasp it in a matter of days, or hours. It's like standing on the shoulders of giants.

4
  • 6
    log(N) for sorting an array would be beyond awesome. Sep 1, 2012 at 13:37
  • @Konrad: crap, I first started writing about a binary search but then wanted to show (what I think is) a more common problem. Fail.
    – Lou
    Sep 2, 2012 at 11:19
  • @KonradRudolph Except that you can prove it's not possible and that n logn is actually a lower bound for comparison based sorting algorithms.
    – phant0m
    Sep 22, 2012 at 11:51
  • 4
    @phant0m Congratulations, you’ve missed the obvious sarcasm in my comment. Sep 24, 2012 at 10:47
7

They are not insightful in new ways about human cognition at all.

I’m not sure how you reached this conclusion but it’s completely wrong. The opposite is true: algorithms offer the deepest insight into human cognition ever. This is formalised in the Church–Turing thesis. The conjecture is about the computability of functions but it has a very important corollary about our intuition of computability.

It effectively states that the human mind is in principle limitless (sometimes termed a “universal constructor”; not to be confused with the similar but distinct concepts of “universal assembler” and “von Neumann universal constructor”).

If the hypothesis is true, then (according to David Deutsch, The Beginning of Infinity) the (human) mind is unique in all of the known Universe: it alone is capable of causing a sustained effect over the rest of the physical Universe.

The argument becomes a bit convoluted but it essentially reduces to the point that everything else on our world, our solar system and even our galaxy is limited in scope: go away far enough and its effect vanishes. A creative mind (like the human mind) alone is able of extending its own physically imposed limits, because our minds are able of generating knowledge.

If you’re interested in human cognition, I recommend you read Deutsch’s book which explains this in great detail. And all of this follows directly from … the insightfulness of algorithms, in particular the Church–Turing thesis.


Apart from that, algorithms are interesting once they cause you a shift in cognition. For instance, once you first understand recursion, or dynamic programming, or transitivity, it’s as if a small light goes on in your head – you have an insight. So algorithms are, in the primary sense of the world, insightful.

2

Algorithms are part of your basic toolkit for solving problems. If you have to reinvent a particular type of sort routine every time you need things in a particular order, you are a) going to be slow to develop a solution, and b) almost certainly get it wrong (or at least not right).

When is it best to use a B+-tree? When is locality of reference important and when can you ignore it? Do you always need to fully normalize your relational database design, or are there times when denormalizing it will be better? What patterns work well with interprocess (or interthread) locking, and which ones grind to a halt? Etc., etc.

If you don't understand how to think about algorithms (created by other people or by yourself), then you will never advance past being a simple coder.

2

What algorithms demonstrate about human cognition is that it is possible for us to create nearly infinitely complex applications, with only the requirement to solve relatively minor, immediate problems. This because generations of previous problems have been solved and encapsulated in algorithms, which can simply be used opaquely without knowledge of how those algorithms were developed or how they function.

2

can tell you why fractals are awesome, why the golden ratio is awesome, why origami is awesome and scientific applications of all the above

Algorithms are "awesome" because they enable all those things. How do you tell someone how to create a given fractal structure? You give them an unambiguous set of instructions. That's an algorithm. How do you compute phi? You follow an algorithm. If the general notion doesn't inspire you, it's probably because it's already so deeply engrained in your daily life that you simply take it for granted. If you can't think of scientific applications of algorithms, though, you either don't understand the concept or you don't know the first thing about science.

I was expecting algorithms to be shattering preconceptions and mind-altering but time and time again they fail miserably.

Turning just to algorithms for computing, perhaps your expectations are inflated. It's hard to be floored by anything when you're expexcting to be floored. nevertheless, there are plenty of algorithms that are beautiful in some sense or that required impressive insight. These may not be the ones you're learning in class right now, but if you don't think that an algorithm like quicksort is at least pretty nifty you might be in the wrong field. If you're not impressed that there are algorithms that allow databases containing billions of records to be searched instantly, you're really not trying. If you don't find it "awesome" that relatively straightforward algorithms enable millions of computers to send each other zillions of packets of data very reliably, there's nothing I can say that'll impress you.

1

They are not insightful in new ways about human cognition at all.

Algorithms can be considered as constructive proofs of the existence of a solution to the considered problem. And similarly, a constructive proof of existence can be turned in an algorithm for computing the result.

And proofs, even alternative proofs when one already exists, provide insight about the problem at hand.

0

Others have already addressed algorithms in the cookbook sense, so I'll try to address the theory.

It's easy to get the idea that a simple and quick algorithm is adequate - and then your code gets used for real-world problems with larger data sets and it's not just slow, it's unusable.

A lot of the theory is about how time and space requirements grow as the problem size increases, and it's important because naive choices are often very fast on small data sets, but with unacceptable growth.

A lot of programmers never need to analyze an algorithm for themselves, and many get away with misunderstandings about the theory, but anyone who thinks a bubblesort is an adequate way to sort a potentially huge dataset should be shot.

Another thing is that while a lot of basic algorithms are precisely that, some of the ideas you encounter for more sophisticated algorithms really are surprising and definitely awesome.

But... well, if shattering preconceptions is your yardstick, you first need relevant preconceptions to shatter. Unless it's an understanding of what exponential time (or worse) really means as your problem sizes increase, algorithm theory doesn't really aim to shock.

0

One more point - if you're looking for algorithms that bear any semblance to human cognition, then perhaps you've simply haven't been exposed to them during your studies. I'm talking mostly about topics from the field of artificial intelligence (expert systems, neural networks, metaheuristics), which are usually taught in advanced classes, or even not at all.

1
  • Can I be made aware for the reason of the downvote? It specifically addresses the issue of similarity to human cognition referenced in the question.
    – mikołak
    Jan 29, 2013 at 18:34
-1

Have you ever Googled something?

How long did it take for you to get results? I bet it was pretty quick. That's down to an algorithm.

How many results did it return to you? Again, that's down to an algorithm.

How relevent/correct were the results to what you Googled? Algorithm.

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