– What is an algorithm?

287 views

– What is an algorithm?

In: 8

20 Answers

Anonymous 0 Comments

Let’s say that I gave you a shuffled stack of cards with a bunch of different people’s names on them, and told you to put them in alphabetical order. How would you do it?

Well, there’s a few ways. You could start laying the cards out in a line, roughly where you expect them to be in the alphabet. Then add cards on either side of the ones you already put down, depending on the letter. Or maybe you could flip through all the cards, pull out all of the A names, then go back through and do it again for all the B names…

Some of these ways will be faster than others. But you could write your way down as a set of simple instructions that anyone else could follow with their own set of names to sort. That set of instructions — the process by which you sort the cards — is an algorithm.

Remember, that computers are very, very stupid. They are very good at following very precise instructions, but they are not good at thinking on their own. If you want a computer to sort names in alphabetical order, you need to tell them exactly how to do it. Some of those ways will be super fast, where other ways might take the computer a while.

Computer scientists like to come up with many different clever ways of doing things like sorting names. The actual code, or which computer coding language you use to actually write the algorithm, isn’t as important as making sure the algorithm is efficient and well designed. If you have millions of names to sort, the right algorithm might be hundreds of times faster than a slower one.

When Facebook had to write it’s “news feed“ feature, someone needed to design the specific set of instructions and criteria that determine which posts get put into your feed. These rules are an algorithm. These days in pop culture, it’s just called “the algorithm“ because the exact set of rules are secret, and Facebook won’t tell you exactly what they are.

Anonymous 0 Comments

It is just a structured way of solving problems.

In computer science we usually mention an algorithm in the context of recursion; which means you call the same set of instructions multiple times to achieve an end result.

Say you have algorithm ‘mow lawn’, you might look at your lawn and say:

1 – Retrieve mower
2 – Start mower
3 – Mow row 1
4 – Mow row 2
5 – Mow row 3
6 – …7
7 – Pick up clippings
8 – Wake up neighbors with leaf blower
9 – Store all equipment

You can do that same task with recursion, and you can generalize it against lawns of all shapes and sizes by calling ‘mow row’ repeatedly and using general method to determine how many times you need to call the mow row function. Without recursion I have to program my instructions bespoke to the lawn I intend to mow. With recursion I can measure things and instead of listing out each row I need to mow; I might do something like:

1 – Measure the mower deck
2 – Measure the unmowed lawn
3 – x = width of (unmowed)lawn
4 – y = width of mower deck
5 – While x > y mow row <– I repeatedly mow until x is now longer greater than y, which should leave one strip (you don’t want to say ‘while x >= y’ because then you will never leave the loop)
6 – Mow last row
7 – Pick up clippings
8 …

Anonymous 0 Comments

Thanks all for the explanations!

Anonymous 0 Comments

Thanks all for the explanations!

Anonymous 0 Comments

One thing that made me understand algorithms, is having to learn them to solve a Rubik’s cube. There’s repeated steps taken to solve any cube puzzle–any moving puzzle really. But, those repeated patterns are algorithms. I solve the Rubik’s cube the same way every time. If I mess up, cause I’m certainly no pro, that means I missed a completed turn in the algorithm, and I usually have to start over, or find where the pattern left off.

Anonymous 0 Comments

One thing that made me understand algorithms, is having to learn them to solve a Rubik’s cube. There’s repeated steps taken to solve any cube puzzle–any moving puzzle really. But, those repeated patterns are algorithms. I solve the Rubik’s cube the same way every time. If I mess up, cause I’m certainly no pro, that means I missed a completed turn in the algorithm, and I usually have to start over, or find where the pattern left off.

Anonymous 0 Comments

In a computer science class I took, algorithms were defined as a finite set of instructions which will produce an answer to a question with infinite variations.

The fact that the question must have infinite variations is only relevant because, if a question has a finite set of variations, then you could memorize all the possible answers and record them in a table somewhere and avoid using an algorithm.

In casual day-to-day usage, the word seems to refer to anything not-sentient which makes a decision.

Anonymous 0 Comments

You know when Dad gets you Legos and you follow the steps to build those dinosaurs in the instructions? That’s an algorithm! You know how each instruction book is different? That’s because each instruction book is a different algorithm for building a different dinosaur with different pieces!

Anonymous 0 Comments

In a computer science class I took, algorithms were defined as a finite set of instructions which will produce an answer to a question with infinite variations.

The fact that the question must have infinite variations is only relevant because, if a question has a finite set of variations, then you could memorize all the possible answers and record them in a table somewhere and avoid using an algorithm.

In casual day-to-day usage, the word seems to refer to anything not-sentient which makes a decision.

Anonymous 0 Comments

You know when Dad gets you Legos and you follow the steps to build those dinosaurs in the instructions? That’s an algorithm! You know how each instruction book is different? That’s because each instruction book is a different algorithm for building a different dinosaur with different pieces!