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?

Jessica
  • 111
  • 1
  • 2
  • 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. – Ozair Kafray Sep 01 '12 at 05:11
  • 7
    Perhaps you should consider switching to Psychology? It sounds like you're much more interested in that topic.. – Izkata Sep 01 '12 at 05:29
  • 5
    Read http://www.amazon.com/G%C3%B6del-Escher-Bach-Eternal-Golden/dp/0465026567/ref=sr_1_1?s=books&ie=UTF8&qid=1346478324&sr=1-1&keywords=goedel%20escher%20bach. Maybe you'll understand. – Matthew Flynn Sep 01 '12 at 05:45
  • 1
    Read this question and its answers: [Which hashing algorithm is best for uniqueness and speed?](http://programmers.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed) - Fascinating! – yannis Sep 01 '12 at 06:26
  • 2
    programs are just algorithms phrased so computers can understand them. –  Sep 01 '12 at 07: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 01 '12 at 09:26
  • 2
    @OzairKafray Regardless of their purpose, they **do** offer new insights into human cognition (someone already mentioned *Gödel, Escher, Bach*). – Konrad Rudolph Sep 01 '12 at 13:36
  • 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 01 '12 at 14:05
  • 1
    Reasons for closing this question: (1 of 2) "Special" and "awesome", as used in this question, is a purely subjective finding from an individual. An individual (even a programmer) need not find algorithms special or awesome, in order to do programming or to benefit from it -- the latter ones are the main themes of this site. – rwong Sep 01 '12 at 23:24
  • 2
    Reasons for closing this question: (2 of 2) Algorithms are prescribed steps for a computer to solve problem. The question being asked here is akin to asking "Why problem solving is so special", or even "Why computers are so special", which may be an interesting question from a humanistic or social science point-of-view, but is uninteresting to programmers (the audience of this site), who take this to be self-evident. – rwong Sep 01 '12 at 23:24
  • If asking about "awesomeness" of something isn't an example of Bad Subjective, I don't know what is :/ I've already read this question multiple times and don't understand what the author thinks algorithms "fail miserably" at. Maybe at shattering preconceptions, or mind altering? I suggest using drugs! – Andres F. Jan 28 '13 at 20:52
  • There is absolutely nothing special (or even exciting) in algorithms. But there is a mind-shattering algorithmic information theory. – SK-logic Jan 28 '13 at 23:39
  • A cynical view is that algorithms are special because Computer Science professors think they are special. In practice most programming by most programmers rarely involves algorithms. For example, every CS algorithm class will spend time on sorting. Yet everyone uses library functions and never writes sorting code from scratch. Well maybe a few dozen do. – CWallach Jan 29 '13 at 00:40
  • @CWallach Using a library function in your own code is also an algorithm, if you understand the term to mean "following a series of steps in order to produce a result"; it's just that one of those steps is "call this library function". Also, _someone_ has to write that library! – Andres F. Jan 29 '13 at 20:46

11 Answers11

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.

zxcdw
  • 5,075
  • 2
  • 29
  • 31
  • 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. – Evan Plaice Jan 25 '13 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 '13 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.

Arseni Mourzenko
  • 134,780
  • 31
  • 343
  • 513
  • 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 01 '12 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?" – Arseni Mourzenko Sep 01 '12 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. – Evan Plaice Jan 25 '13 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.

Lou
  • 265
  • 1
  • 7
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.

Konrad Rudolph
  • 13,059
  • 4
  • 55
  • 75
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.

Peter Rowell
  • 7,468
  • 2
  • 29
  • 33
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.

MebAlone
  • 729
  • 1
  • 5
  • 9
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.

Caleb
  • 38,959
  • 8
  • 94
  • 152
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.

AProgrammer
  • 10,404
  • 1
  • 30
  • 45
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.

mikołak
  • 231
  • 1
  • 8
  • 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 '13 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.

James
  • 4,328
  • 3
  • 21
  • 25