Algorithm
Appearance
An Algorithm is like a [cooking recipe] for [computers]. It tells them, one step after another. In cooking, some recipes are harder to do than others, because they need more complex steps or more time to finish. Its the same thing for Algorthms, some are easier ot do (better) than ohers. The thing used to measure how hard an algorithm is, is called [Complexity]
An example algorithm for sorting a deck of cards by colors and numbers would be
Sorting by colors
- Take a card from the deck, look at its color.
- If there is already a stack of cards with that color, put the card on the stack with the same color.
- If there is no stack with the same color cards, create a new stack with that color, and put the card on it.
Sorting by numbers
When you have run out of cards, you are left with one stack for each color. With easch such stack:
- Take a card from the stack A
- If the stack B is empty, put that card on the stack B
- If you still have the card, compare its value to the card on top of stack B.
- If the value of your card is higher than that on the stack B, put the card on top of stack B
- Put the card below the topmost card on stack B.
Once you run out of cards from stack A, and you have not put a card below anorther, you are done. Else change the names of stacks A and B, and do again.