Algorithms: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
===What does algorithm mean?=== | |||
<!-- | <!-- | ||
A mechanical, fairly detailed description of getting a particular thing done, a particular method towards a particular goal | A mechanical, fairly detailed description of getting a particular thing done, a particular method towards a particular goal | ||
Line 33: | Line 33: | ||
--> | |||
====What do they look like?==== | |||
<!-- | |||
Depends, mainly on the complexity, and on what it does. | |||
There are a lot of things you can describe fully with words, and a little math. | |||
Say, bubble sort is an algorithm that, in English, goes something like "step though a list one at a time. At each position, look at the pair. If the are not in the right order, swap them. Repeat going through the list until you didn't need to swap anything". | |||
Writing down the same in [[pseudocode]] is not much longer than that: {{verify}} | |||
<syntaxhighlight lang="python"> | |||
for i in 1 through length-of( L ) | |||
for j in length-of( L ) through i + 1 | |||
if L[j-1] > L[j] then | |||
Exchange L[j-1] with L[j] | |||
</syntaxhighlight> | |||
...and {{comment|(even if you would need to rewrite it into ''actual'' code before it actually would run)}} might include some more details, sometime edge case handling, that a worded version does not explicitly mention . | |||