What are linear algorithms?

A linear algorithm is like a straight line, it grows at a steady pace as you add more things to work with.

Imagine you're lining up your toys to clean them. If you have 5 toys, you pick each one up and put it away, that’s 5 steps. If you get 10 toys, you do 10 steps. No matter how many toys you have, you just add one more step for each new toy. That's what a linear algorithm does, it takes as many steps as there are items to process.

Like a Line of People Waiting

Think about a line at the ice cream shop. If 3 people join the line, they wait for 3 turns. If 10 people come, they wait for 10 turns. Each person adds one more step in the line, just like how a linear algorithm works with data.

No Hops or Jumps

Some algorithms are faster, they can jump ahead or do things all at once. But linear ones are simple: they go one by one, steady and sure, no matter how long the line gets. A linear algorithm is like a straight line, it grows at a steady pace as you add more things to work with.

Imagine you're lining up your toys to clean them. If you have 5 toys, you pick each one up and put it away, that’s 5 steps. If you get 10 toys, you do 10 steps. No matter how many toys you have, you just add one more step for each new toy. That's what a linear algorithm does, it takes as many steps as there are items to process.

Take the quiz →

Examples

  1. Counting the number of apples in a basket one by one
  2. Adding up your weekly allowance
  3. Measuring the distance between two cities on a map

Ask a question

See also

Discussion

Recent activity