Full Version: What is an algorithm?
pandy
Well, I know what it is, sort of. But I've never understood the difference between a (computer) algorithm and a short procedural program or script. Thought it's about time I find out. CharlesEF
I will admit that I don't know the 'official' meaning but I have always understood that a algorithm is a mathematical formula to perform a specific task. I wouldn't consider a computer program or script an algorithm.

Think about the day of the week. You could write a program or script to determine the day of the week. However, that program/script may be quite large. If you used an algorithm then you would only need a few lines of code. The algorithm would be the function call in that program/script.

I hope I haven't confused you more.
Christian J Clear as mud:

https://en.wikipedia.org/wiki/Algorithm#Computer_algorithms
https://en.wikipedia.org/wiki/Script_(computer_programming)
pandy

I will admit that I don't know the 'official' meaning but I have always understood that a algorithm is a mathematical formula to perform a specific task. I wouldn't consider a computer program or script an algorithm.

Think about the day of the week. You could write a program or script to determine the day of the week. However, that program/script may be quite large. If you used an algorithm then you would only need a few lines of code. The algorithm would be the function call in that program/script.

I hope I haven't confused you more.

Well, I was already confused so... So you mean an algorithm is part of a program rather than a standalone program? But in that case, isn't it just a subroutine?

BTW I know there were math algorithms before there were computers, but I have no ambitions to understand those. pandy Clear as mud:

https://en.wikipedia.org/wiki/Algorithm#Computer_algorithms
https://en.wikipedia.org/wiki/Script_(computer_programming)

Yeah, I've read that. And look at the example they give. That's a program/script to me. https://en.wikipedia.org/wiki/Algorithm#Algorithm_example
CharlesEF Clear as mud:

https://en.wikipedia.org/wiki/Algorithm#Computer_algorithms
https://en.wikipedia.org/wiki/Script_(computer_programming)

I agree, those links make me confused. CharlesEF

So you mean an algorithm is part of a program rather than a standalone program? But in that case, isn't it just a subroutine?

Yes, it would be considered a subroutine. And I see how easy it is to confuse an algorithm with a computer program. My understanding of an algorithm comes from a math background. If I were to translate that into computer talk then I would say a computer program could be converted into an algorithm if you can use mathematical formulas to reduce the code to only a few lines. That would be an algorithm.
Christian J

I've never understood the difference between a (computer) algorithm and a short procedural program or script.

But is there a distinct difference, maybe the terms belong to different categories, or overlap?

According to Wikipedia:
The term "scripting language" is also used loosely to refer to dynamic high-level general-purpose languages [...] with the term "script" often used for small programs (up to a few thousand lines of code) in such languages

--so a script is a small program in a high-level general-purpose language.

QUOTE
look at the example they give. That's a program/script to me. Seems an algo can be written as a program/script (but also in English prose, like in the example), and a program can be a script? In other words, an algo can be a script? pandy

But is there a distinct difference, maybe the terms belong to different categories, or overlap?

If not, why don't we ever hear someone talk about Google's scripts?

QUOTE
According to Wikipedia:
The term "scripting language" is also used loosely to refer to dynamic high-level general-purpose languages [...] with the term "script" often used for small programs (up to a few thousand lines of code) in such languages

--so a script is a small program in a high-level general-purpose language.

But what is an algorithm? QUOTE

QUOTE
look at the example they give. That's a program/script to me. Seems an algo can be written as a program/script (but also in English prose, like in the example), and a program can be a script? In other words, an algo can be a script? Nah, the prose is pseudo code, or a verbal description of the intention and procedure of the script/algorithm.

About programs vs. scripts. I tend to generally call them scripts if they aren't compiled. And if they are stand alone and not huge. Like this forum I would call a program rather than a script. Or I guess it could be called a system of scripts or something like that, but not "a script". "What forum script do you prefer?" - sounds batty. Compiled stuff I always call programs, no matter how small they are. But that's me - I have no idea if I use the terms in a totally kosher way.
pandy

So you mean an algorithm is part of a program rather than a standalone program? But in that case, isn't it just a subroutine?

Yes, it would be considered a subroutine. And I see how easy it is to confuse an algorithm with a computer program. My understanding of an algorithm comes from a math background. If I were to translate that into computer talk then I would say a computer program could be converted into an algorithm if you can use mathematical formulas to reduce the code to only a few lines. That would be an algorithm.

I can see that. That pretty much sums up what I know about math algorithms. But if we stay in the computer world it gets muddy, I think.

Or has algorithm become a buzz word? Makes things sound fancy and a little mysterious maybe?
pandy
If this is true, even I use algorithms. There are several other YouTube clips trying to explain it, but this was the only one I saw I understood. But it can't be that simple, can it?
Christian J

If not, why don't we ever hear someone talk about Google's scripts?

I'd say Google's original algorithm is their link popularity idea (probably patched as a house of cards by now), not the exact program code that's used for calculating it.

BTW Googlebot is probably a compiled program, not a script. QUOTE
Nah, the prose is pseudo code, or a verbal description of the intention and procedure of the script/algorithm.

Isn't the latter the definition of an algorithm? Wikipedia: "An unambiguous specification of how to solve a class of problems". Imagine you tried to give instructions to Alexa/Siri/Cortana, wouldn't such instructions qualify as an algorithm? QUOTE
About programs vs. scripts. I tend to generally call them scripts if they aren't compiled. And if they are stand alone and not huge.

#metoo

QUOTE
Like this forum I would call a program rather than a script. Or I guess it could be called a system of scripts or something like that

I wouldn't call it neither "a program" nor "a script". A system of scripts sounds reasonable, or just "forum software".

QUOTE
Compiled stuff I always call programs, no matter how small they are.

Same here.
CharlesEF
Since the advent of computers the waters have indeed become muddy. Let me try to explain it differently.
x = 5 MOD 2
Convert this into PHP
\$x = 5 % 2;
Is this an algorithm? According to the PHP manual the modulo command returns the remainder of 5 divided by 2. So, exactly what is that line of code used for? You could turn it into a function, like this:
CODE

function isOddOrEven(input)
{
return input % 2;
}

Anyway, none of that code makes this an algorithm, IMHO.
What I would consider an algorithm is the implementation of the modulo command itself.

I hope I make some sense. I've tried to convert my math background into computer talk, maybe not too well.
Darin McGrew
Well, I know what it is, sort of. But I've never understood the difference between a (computer) algorithm and a short procedural program or script. Thought it's about time I find out. The way I learned it, a program or a script or a subroutine or whatever you want to call it is an actual implementation of something. In contrast, an algorithm is the high-level concept that you're trying to implement.

For example, if you're trying to sort a list of items, there are a number of different ways to sort them.

One basic algorithm is a bubble sort. The concept is to compare the first item with the second item, and swap them if they're out of order. Then repeat with the second and third, the third and fourth, the fourth and fifth, and so on, until you've processed the entire list. At this point, the last item is correct, but the others may or may not be correct, so you repeat the whole process for the entire list except the last item. And then you repeat the whole process for the entire list except for the last two items, and except for the last three items, and so on.

The concept of how to sort a list of items this way is the algorithm. But the concept doesn't let you sort anything, any more than the concept of an automobile lets you drive down the street.

An actual program/script/function/procedure/subroutine/whatever may implement this algorithm. To sort something, you can run the program/script/function/procedure/subroutine/whatever. In the same way, a particular minivan or coupe or sedan may implement the concept of an automobile, and you can use that implementation to drive down the street.

Anyway, does this help?
pandy
Oh! So an algorithm isn't actual code? More a description of what should be done? Or maybe rather a description of the method that should be used.

But then how is this "concept" described, surely not in plain English?
Darin McGrew
Oh! So an algorithm isn't actual code? More a description of what should be done? Or maybe rather a description of the method that should be used.
It's a description of the method. For example, there are many, many algorithms for sorting a list. The "what should be done" is the same for all of them: the list should be sorted when you're done. But it's the "method" or the "how" that differs, and that makes one algorithm better than another in a given situation.

But then how is this "concept" described, surely not in plain English?
There isn't really a special "algorithm language". An algorithm is supposed to be understood by humans, so it's described in human languages. The implementations/programs/whatever are written in computer languages, because they need to be understood by computers.
pandy
Wow, that simple... Thanks Darin, I had no idea. 