What is an algorithm? |
What is an algorithm? |
pandy |
Jul 22 2018, 02:07 AM
Post
#1
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
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.
|
Darin McGrew |
Jul 26 2018, 09:06 PM
Post
#2
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
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 |
Jul 27 2018, 06:14 AM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
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 |
Jul 28 2018, 12:43 AM
Post
#4
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
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 |
Jul 28 2018, 08:29 AM
Post
#5
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Wow, that simple... Thanks Darin, I had no idea.
|
Lo-Fi Version | Time is now: 24th April 2024 - 04:21 PM |