Algorithm = exact steps, in order
You tell a friend the way to your house. You say exact steps, in order.
Loading lab…
That list of steps is an algorithm.
Step 1 of 5
- Step 1: move right.
- Step 2: move right.
- Step 3: move down.
- Step 4: move down.
- Step 5: move down. The parcel reaches the gate.
An algorithm is an exact list of steps, in order.
Order matters
Socks, then shoes: easy. Shoes, then socks: it fails.
A grid is rows and columns of squares. A move past its edge does nothing. Start at the top-left corner.
- Up, down, right. "Up" has no square above, so nothing happens. "Down" moves one down. "Right" moves one right. You end one down and one right.
- Down, up, right. "Down" moves one down. "Up" moves back to the top. "Right" moves one right. You end one right.
Same steps. A different order gives a different place.