Algorithm - Simple English Wikipedia

# Algorithm

### From Wikipedia, a free encyclopedia written in simple English for easy reading.

An algorithm is like a cooking recipe for computers. It tells a computer what to do, step by step.

In cooking, some recipes are harder to do than others, because they take more time to finish or have more things to keep track of. It's the same for algorithms, and algorithms are better when they are easier for the computer to do. The thing that measures how hard an algorithm is is called complexity.

## [edit] Sorting by colors

This is an example of an algorithm for sorting a stack of cards with colors on them into piles of the same color:

1. Take a card from the stack and look at its color.
2. If there is already a stack of cards of that color, put the card on the stack with the same color.
3. If there is no stack with cards of that color, make a new stack with that color, and put the card on it.

Do this algorithm until there are no cards left in your hand.

## [edit] Sorting by numbers

This is an example of an algorithm for sorting a stack of cards with many different numbers, so that the numbers are in order.

You start with a stack of cards that haven't been sorted. Call this "stack A". You're also going to make a "stack B", but it starts with no cards in it. Then follow these steps:

1. Take a card from stack A.
2. If there are no cards in stack B, put the card you took in stack B.
3. If you still have the card, see if it has a higher or lower number than the card on the top of stack B.
4. If your card has a higher number than the one on top of stack B, put the card on top of stack B.
5. If your card has a lower number than the one on top of stack B, or if the numbers are equal, put your card under the top card on stack B, and remember that you did this.

When you run out of cards in stack A:

- If you didn't put any cards under another card when you followed those steps, you're done.
- If you did, move stack B to stack A and start over.

## [edit] Putting algorithms together

If you have cards with colors and numbers on them, you can sort them by color and number if you do the "sorting by colors" algorithm, then do the "sorting by numbers" algorithm to each colored stack, then put the stacks together.

The sorting by numbers algorithm is harder to do than the sorting by colors algorithm, because you may have to do the steps again many times. You would say that sorting by numbers is more complex.

Retrieved from "http://simple.wikipedia.org../../../a/l/g/Algorithm.html"

Category: Mathematics

##### Views

- Article
- Talk
- Newest version

##### Search

##### In other languages

- Afrikaans
- Aragonés
- Asturianu
- Bosanski
- Български
- Català
- Česky
- Dansk
- Deutsch
- Eesti
- Ελληνικά
- English
- Español
- Esperanto
- فارسی
- Français
- Galego
- 한국어
- Hrvatski
- Bahasa Indonesia
- Interlingua
- Íslenska
- Italiano
- עברית
- ქართული
- Latviešu
- Lëtzebuergesch
- Lietuvių
- Magyar
- Nederlands
- 日本語
- Norsk (bokmål)
- Polski
- Português
- Română
- Русский
- Shqip
- Slovenčina
- Slovenščina
- Српски / Srpski
- Srpskohrvatski / Српскохрватски
- Basa Sunda
- Suomi
- Svenska
- Tagalog
- ไทย
- Tiếng Việt
- Türkçe
- Українська
- 中文