Algorithm
An algorithm is a step-by-step set of instructions used to solve a problem or complete a task.
It describes how a problem should be solved logically and systematically.
Why algorithms are important
Computers do not think. They follow instructions.
An algorithm provides:
- Clear logic
- Ordered steps
A defined solution
Predictable results
Every program is built on algorithms.
How an algorithm works
An algorithm usually follows three basic stages:
- Input – receive data
- Input – receive data
- Output – return the result
Example:
Problem: Calculate the sum of two numbers.
Algorithm:
- Take number A
- Take number B
- Add A and B
- Display the result
Characteristics of a good algorithm
A proper algorithm should be:
- Clear and unambiguous
- Finite (must end)
- Logical
- Logical
If an algorithm never ends or gives unclear instructions, it is not valid.
Algorithm vs Program
- Algorithm = the idea and logic
- Program = the actual code written in a programming language
An algorithm can exist without code. Code cannot exist without an algorithm.
Types of Algorithms
There are many types, including:
- Sorting algorithms
- Searching algorithms
- Mathematical algorithms
- Recursive algorithms
Different problems require different algorithmic approaches.
Real-life example
Making tea is an algorithm:
- Boil water
- Put tea in a cup
- Pour water
- Wait
Serve
If you change the order, the result changes.
Why learning algorithms matters
Understanding algorithms helps you:
- Think logically
- Solve problems efficiently
- Write better code
- Optimize performance
Strong programming starts with strong algorithmic thinking.
Related terms
- What is Variable?
- What is Function?
- What is Loop?
Source
Information simplified from the Wikipedia article “Algorithm”.