THE INDIAN INTERNATIONAL SCHOOL – DSO
What is an Algorithm?
An algorithm is a set of commands that must be followed for a computer to perform
calculations or other problem-solving operations.
Basic structure of Problem Solving using computers
• Problem: A problem can be defined as a real-world problem or real-world instance
problem for which you need to develop a program or set of instructions. An algorithm is
a set of instructions.
• Algorithm: An algorithm is defined as a step-by-step process that will be designed for a
problem.
• Input: After designing an algorithm, the algorithm is given the necessary and desired
inputs.
• Processing unit: The input will be passed to the processing unit, producing the desired
output.
• Output: The outcome or result of the program is referred to as the output.
Now, use an example to learn how to write algorithms.
Algorithm: Making Hot Chocolate (Real Life Example)
1. Start.
2. Pour the milk into a small saucepan.
3. Heat the milk on the stove over medium heat until it starts to simmer (small bubbles
form around the edges).
4. Add the cocoa powder to the saucepan.
5. Stir the cocoa powder into the milk until it's completely dissolved.
6. Taste the hot chocolate and add sugar if desired, stirring until dissolved.
7. Pour the hot chocolate into a mug.
8. Top with mini marshmallows if desired.
9. Serve and enjoy your hot chocolate!
10. End.
Algorithm to add two numbers
Step 1: Start.
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum.
Step 6: Stop.
Algorithm – Logging in to the School Computer Safely (with Authentication)
Step 1: Turn on the computer by pressing the power button.
Step 2: Wait for the login screen to appear.
Step 3: Click on your user profile.
Step 4: Enter your username (your special ID).
Step 5: Enter your password (a secret word only you know).
Step 6: This is called authentication – the computer checks if your username and password
match.
Step 7: If the information is correct, the computer lets you in.
Step 8: If it’s wrong, try again or ask a teacher for help.
Step 9: After finishing your work, log out to keep your account safe.
Advantages of Algorithms:
• It is easy to understand.
• An algorithm is a step-wise representation of a solution to a given problem.
• In an Algorithm the problem is broken down into smaller pieces or steps hence, it is
easier for the programmer to convert it into an actual program.