What is an algorithm? Simple Explanation and Real-Life Example
- Quescol 1-Minute Read
- Let’s Understand in Depth
- What is an Algorithm?
- Key Features of an Algorithm
- 1. Finiteness
- 2. Definiteness
- 3. Input
- 4. Output
- 5. Effectiveness
- How to Express an Algorithm
- 1. Natural Language:
- 2. Flowchart:
- 3. Pseudocode:
- Real-Life Example of an Algorithm – Total Shopping Amount
- Problem:
- Algorithm to Calculate Total Price:
- Algorithm: Calculate Total Shopping Amount
- How is This Algorithm Used in Programming?
- Why Are Algorithms Important?
- Algorithms in Daily Life
- What is Algorithm Complexity?
- 1. Space Complexity
- How to Calculate Space Complexity?
- Example: Linear Search
- 2. Time Complexity
- How to Calculate Time Complexity?
- Example: Linear Search
- Conclusion
- Frequently Asked Questions (FAQs)
Algorithms can be defined as the set of instructions structured to solve a problem. It is a step-by-step procedure to solve the problem. These steps are generally written in English to understand them easily and later convert them into computer programs. These steps together are called algorithms.
Let us consider an example, Suppose you went shopping and want to know how much money you spent in total. You take your shopping list and start adding the prices of each item using a calculator. An algorithm can do the same thing for you, it follows a set of simple steps to add all the prices one by one and give you the total amount you spent.
Quescol 1-Minute Read
An algorithm is a step-by-step set of instructions to solve a problem. It tells the computer what to do and in what order, just like a recipe guides you to make a dish.
Key Features of an Algorithm:
- Finiteness – It must end after a certain number of steps.
- Definiteness – Every step should be clear and easy to understand.
- Input – It should take some data before starting.
- Output – It must give at least one useful result.
- Effectiveness – Each step should be simple and practical.
How to Express an Algorithm:
- Natural Language – Written in plain English.
- Flowchart – Shown using diagrams and symbols.
- Pseudocode – Written like simple code for easy understanding.
Algorithm Complexity:
It shows how much time and memory an algorithm uses to finish its task.
- Space Complexity:
Measures how much memory an algorithm needs.
Formula:S(P) = C + Sᵥ(I)
WhereS(P)= total space used,C= fixed space,Sᵥ(I)= variable space (depends on input). - Time Complexity:
Measures how long an algorithm takes to run.
Formula:T(P) = C + Tᵥ(I)
WhereT(P)= total time used,C= constant time,Tᵥ(I)= variable time (depends on loops or input size).
Let’s Understand in Depth
What is an Algorithm?
An algorithm is a step-by-step procedure or a set of instructions that helps solve a specific problem or perform a particular task.

In simpler words, an algorithm tells the computer what to do and in what order to do it, just like a recipe in a cookbook tells a chef how to make a dish.
Key Features of an Algorithm
Some of the key feature of an algorithm are:
1. Finiteness
A good algorithm must always end after a certain number of steps. It should not go on forever or get stuck in a loop. This means the algorithm must have a clear stopping point where it finishes its work and gives the result.
Example: When adding the prices of all shopping items, the process stops after the last item is added — it doesn’t keep repeating.
2. Definiteness
Every step in an algorithm should be clear and easy to understand. There should be no confusion or double meaning in any instruction. Each step must tell exactly what to do so that anyone can follow it.
Example: While adding shopping prices, the instruction “add the next price to the total” is clear and simple.
3. Input
An algorithm should accept zero or more inputs before starting. Inputs are the data needed to perform the task.
Example: In the shopping total example, the list of item prices is the input given to the algorithm.
4. Output
An algorithm must produce at least one output that shows the result of the process. The output should be meaningful and directly related to the input.
Example: After adding all the shopping prices, the total amount spent is the output.
5. Effectiveness
Each instruction in an algorithm should be simple, clear, and practical. It should be something that can be easily done with basic operations.
Example: Adding each shopping price one by one is an effective and doable step.
How to Express an Algorithm
1. Natural Language:
In this method, the algorithm is written in plain English sentences. It describes each step in a simple, everyday way. However, it can sometimes be difficult to understand clearly because natural language can be confusing or have multiple meanings. This makes it less suitable for complex problems or for computers to follow directly.
2. Flowchart:
A flowchart represents the algorithm using diagrams and symbols. Each step of the process is shown through shapes such as rectangles (for processes), diamonds (for decisions), and arrows (to show the flow). This method makes it easier to visualize the logic and understand how the algorithm progresses from start to end.
3. Pseudocode:
In pseudocode, the algorithm is written in a structured format that looks similar to programming code but without strict syntax rules. It uses plain English words and logical statements to describe each step clearly. Pseudocode is considered the best way to express an algorithm because it is easy to read, understand, and convert into actual code by programmers.
Real-Life Example of an Algorithm – Total Shopping Amount
Let’s take a real-world example to understand this better.
Imagine you went shopping and bought several items: milk, rice, and potatoes. Now, you want to calculate the total amount you spent.
You could simply take a calculator and start adding each item’s price. But this is exactly what an algorithm does, it follows a sequence of steps to get to the result.
Problem:
You want to find out the total amount spent during shopping.
Algorithm to Calculate Total Price:
Here is a simple algorithm to solve this problem:
Algorithm: Calculate Total Shopping Amount
1. Start
2. Assign a variable to each item (item1, item2, item3, ...)
3. Create a variable “total” which will store the total price.
4. Add all the item prices and store the result in “total”.
5. Display the value of “total”.
6. Stop
How is This Algorithm Used in Programming?
Once we write down an algorithm in simple English (like the example above), a programmer can then convert it into a programming language like C, Java, or Python.
For example, in C language, the algorithm might be implemented like this:
#include
int main() {
int milk, rice, potato, totalPrice;
printf("Enter the price of milk:\n");
scanf("%d", &milk);
printf("Enter the price of rice:\n");
scanf("%d", &rice);
printf("Enter the price of potato:\n");
scanf("%d", &potato);
totalPrice = milk + rice + potato;
printf("Total Price = %d\n", totalPrice);
return 0;
}
Output
Enter the price of milk:
43
Enter the price of rice:
52
Enter the price of potato:
33
Total Price = 128
Why Are Algorithms Important?
Algorithms are the foundation of computer programming. They are the basic set of rules or steps that make every program work properly.
- They help break big problems into small steps:
- When we have a large or complex problem, algorithms help us divide it into smaller, easy-to-handle steps. This makes the task simple and well-organized. For example, if you want to find the total cost of shopping, an algorithm helps by breaking the process into steps like taking the prices, adding them, and showing the total amount.
- They help us think logically and systematically:
- Algorithms teach us to think in a clear and step-by-step way. Instead of guessing, we learn to plan each action carefully and make sure every step makes sense. This logical way of thinking is useful not only in programming but also in solving everyday problems.
- They are used in every kind of software:
- Algorithms are part of all types of software, whether it is a simple calculator, a mobile app, or a complex space program. Every program follows an algorithm to decide what to do and how to do it.
- They are important in data processing, artificial intelligence, and machine learning:
- In modern technology, algorithms help computers analyze data, recognize patterns, and make smart decisions. They are the reason behind things like recommendation systems, voice assistants, and self-driving cars.
Algorithms in Daily Life
Even outside of coding, we follow algorithms every day:
- Getting ready in the morning (wake up → brush → shower → breakfast → go to school/work)
- Baking a cake (gather ingredients → mix → bake → cool → serve)
- Unlocking your phone (press power button → swipe up → enter passcode)
So, algorithms are not just for computers, they’re a part of your daily life too!
What is Algorithm Complexity?
When we create an algorithm, it is important to know how much time and memory (space) it will take to finish the task.
This is called the complexity of an algorithm.
In simple words, algorithm complexity means how much time an algorithm takes to run and how much memory it needs to store all the data while running.
These two things — time and space which decides how efficient an algorithm is.
There are two main parts of algorithm complexity:
- Time Complexity – how long the algorithm takes to finish.
- Space Complexity – how much memory it uses while running.
1. Space Complexity
Space Complexity means how much memory (space) an algorithm needs to store all the data, this includes the input, temporary data, and the output.
If an algorithm needs more memory, it has higher space complexity. If it uses less memory, it has lower space complexity.
How to Calculate Space Complexity?
Space complexity has two parts:
- Fixed Part:
This is the memory that is always needed, no matter what input you give.
It includes things like input variables, output variables, and the size of the program itself. - Variable Part:
This is the memory that changes depending on the size of the input or the way the program runs.
It includes temporary variables, dynamically allocated memory, and recursion stack space.
So, we can write it as:
S(P) = C + Sᵥ(I)
Where:
- S(P) = Total space used by the program
- C = Fixed part
- Sᵥ(I) = Variable part (depends on the input)
Example: Linear Search
Let’s take an example of Linear Search, we search for a number inside a list.
Steps:
- Start
- Take n elements in an array
arr[]and a numberxto search - Compare
xwith each element one by one - If found, print “True”
- If not found, print “False”
- End
Here, there are two main variables:
arr[]→ variable part (depends on how many elements n are in the array)x→ fixed part
So, Space Complexity S(P) = 1 + n.
This means the space depends on how many elements are in the array.
2. Time Complexity
Time Complexity means how long an algorithm takes to complete its task.
It tells us how many steps (or operations) the algorithm performs depending on the input size.
If an algorithm finishes faster, it has lower time complexity.
If it takes more time, it has higher time complexity.
How to Calculate Time Complexity?
Time complexity also has two parts:
- Constant Time Part:
These are instructions that run only once, such as input, output, if-else conditions, or a simple calculation. - Variable Time Part:
These are instructions that run multiple times, such as loops or recursive calls.
So, we can write it as:
T(P) = C + Tᵥ(I)
Where:
- T(P) = Total time used by the algorithm
- C = Constant time part
- Tᵥ(I) = Variable time part (depends on how many times the loop or recursion runs)
Example: Linear Search
Using the same example of searching a number in an array:
Steps:
- Start → constant time
- Take n inputs → variable time (depends on n)
- Compare each element with x → variable time (can happen n times)
- If found, print “True” → constant time
- If not found, print “False” → constant time
- End → constant time
Now, let’s calculate the total time:
T(P) = 1 (step 1) + n (step 2) + n (step 3) + 1 (step 4) + 1 (step 5) + 1 (step 6)
So, T(P) = 2 + 3n, which we write as T(n), it shows time depends on n, the number of elements.
Conclusion
To sum it up, an algorithm is like a recipe for solving problems. It tells the computer (or even a human) what steps to follow to reach the final goal. Whether you’re calculating the total price of shopping items or designing a complex mobile app — algorithms are everywhere.
By understanding and creating algorithms, you learn how to think logically, solve problems efficiently, and build the foundation of programming.
Frequently Asked Questions (FAQs)
1. What is an algorithm in simple terms?
An algorithm is a list of steps that are followed to solve a problem or complete a task.
2. Is an algorithm always written in code?
No, algorithms are first written in plain English or pseudocode. They are later converted into actual programming code.
3. Can children understand algorithms?
Absolutely! With real-life examples like shopping or making noodles, algorithms can be made fun and simple for kids to learn.