The word "algorithm" sounds intimidating. It's not. You follow algorithms every day without realizing it.
An algorithm is just a set of steps
When you make tea, you follow an algorithm:
- Boil water
- Add tea bag to cup
- Pour hot water into cup
- Wait 3 minutes
- Remove tea bag
- Add milk and sugar if needed
- Drink
That's it. A fixed set of steps that produces a result. Algorithms in programming work exactly the same way.
A real programming example
Say you want to find the largest number in a list. Here's the algorithm:
numbers = [4, 7, 2, 9, 1]
largest = numbers[0]
for number in numbers:
if number > largest:
largest = number
print(largest)
Step by step:
- Assume the first number is the largest
- Go through every number in the list
- If a number is bigger than your current largest, update largest
- Print the result
Output: 9
Why algorithms matter
Every app you use runs on algorithms. Google's search results, Instagram's feed, Spotify's recommendations — all algorithms deciding what to show you.
The two things every algorithm needs
- Correctness — it must produce the right answer
- Efficiency — it must do it without wasting time or memory
The one-line summary
An algorithm is a step-by-step recipe for solving a problem. Every program you've ever used runs on them.
Written by Raaga Priya Madhan — CSE student, Bangalore. I write about CS concepts simply. Connect with me on LinkedIn
Top comments (0)