# What is an Algorithm?

October 24, 2020

This post is also available in: हिन्दी (Hindi) العربية (Arabic)

The word algorithm may not seem relevant to kids, but the truth is that algorithms are all around them, governing everything from the technology they use to the mundane decisions they make every day. Algorithms are everywhere and are present in our lives every day, even if we don’t realize it. Algorithms are fascinating and, although some are quite complex, the concept itself is actually quite simple. In this article, we’ll discuss what is an algorithm?

Algorithms have a bigger presence in math and in computer science, and of course, they are not absent in kids’ process of creating an app, designing a game, or learning how to code.

Think of any task, say getting ready for school or preparing a vanilla cake. You follow certain steps in a particular sequence. If you want to bake a vanilla cake from a box mix, you would follow the number of steps written on the box or on the included instructions manual.

Each of these tasks consists of a series of steps that are completed in a particular order. Similarly, an algorithm is a list of steps you give a computer to solve a problem or to get something done.  It is important, however, to explain all the steps in the right order, since machines can get easily confused.

## What is an Algorithm?

The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed in order to get the expected results.

Algorithms help to do a task in programming to get the expected output. The algorithms are language-independent, i.e. they are just plain instructions that can be implemented in any language, and yet the output will be the same, as expected.

The instructions in an algorithm are translated into a form that can be interpreted by a computer, which is generally called a program. A program is machine-dependent and is interpreted by a target machine. Upon execution of instructions by the machine we get the desired result.

Although algorithms are not interpreted and executed by a computer, these play an important role in program writing, understanding and documentation. The other tools that are used for program understanding and documentation are flowchart and pseudocode.

Let’s consider an example of finding the sum of two numbers.

Algorithm to find the sum of two numbers:

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop

C program to find the sum of two numbers:

#include<stdio.h>
int main() {
int num1, num2, sum;
printf("\nEnter two no: ");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("Sum : %d", sum);
return(0);
}

Python program to find the sum of two numbers:

num1 = int(input("enter first number: "))
num2 = int(input("enter second number: "))
sum = num1 + num2
print("sum:", sum)

From the above example you can see that one can translate a given algorithm to a program in any language.

## Origin of the word Algorithm

The term “algorithm” finds its origin from the 9th century, scholar, astronomer, geographer, and mathematician Muhammad ibn Musa al-Khwarizmī who is known for his contributions to the study of algebra. It is the Latinization of his name, which meant ‘the native of Khwãrezm’ (a town in Central Asia, along the borders of modern-day Turkmenistan and Uzbekistan) in Persian, gave English the word algorithm.

Al-Khwarizmī wrote a book in Arabic about Hindu-Arabic numerals, which was later translated into Latin. The Latin translation of the book titled Algoritmi de numero Indorum (in English, Al-Khwarizmi on the Hindu Art of Reckoning). The Latin word algoritmi was then translated into English as ‘algorithm’.

## Characteristics of Algorithm

Not all procedures can be called an algorithm. An algorithm should have the following characteristics:

• Clear and Unambiguous: Algorithms should be clear and unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning.
• Well-Defined Inputs:  If an algorithm requires input, it should be well-defined.
• Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well.
• Finiteness: The algorithm must be finite, i.e. it should not end up in an infinite loop or similar situations.
• Feasible: The algorithm must be simple, generic, and practical, such that it can be executed upon the available resources. It must not contain some future technology, or anything such.
• Language Independent: The Algorithm designed must be language-independent, i.e. it must be just plain instructions that can be implemented in any language, and yet the output will be the same, as expected.

## How to Write an Algorithm?

Although there are no well-defined standards for writing algorithms, there are certain points that must be adhered to. As we know that all programming languages share basic code constructs like loops (do, for, while), flow-control (if-else), etc. These common constructs can be used to write an algorithm.

We write algorithms in a step-by-step manner, but it is not always the case. Algorithm writing is a process that is executed after the problem domain is well-defined. That is, we should know the problem domain, for which we are designing a solution.

## Advantages and Disadvantages of an Algorithm

Following are the advantages of an algorithm:

• It is a stepwise representation of solutions to a given problem, which makes it easy to understand.
• Every step in an algorithm has its own logical sequence so it is easy to debug.
• By using an algorithm the problem is broken down into smaller pieces or steps hence, it is easier for a programmer to convert it into an actual program.
• An algorithm acts as a blueprint of a program and helps during program development.
• An algorithm uses a definite procedure.
• It is easy to first develop an algorithm and then convert it into a flowchart and then into a computer program.
• It is not dependent on any programming language, so it is easy to understand for anyone even without programming knowledge.

Following are the disadvantages of an algorithm:

• Algorithms are time-consuming.
• Big tasks are difficult to put in algorithms.
• Difficult to show branching and looping in algorithms.
• Understanding complex logic through algorithms can be very difficult.

## Encorage Kids To Write Their Own Algorithms

Encourage your child to write out their morning algorithm, or the algorithm for an even simpler task, like brushing their teeth or eating cereal. Without knowing it, they’ll be exploring important computational concepts like repetition (brush bottom left teeth five times), sequencing (put cereal in a bowl and then put in milk), and conditional logic (if the bowl is empty, stop eating).

Challenge your child to be as specific with the instructions as possible. Computers don’t understand your intentions, so if you don’t specify that you need to get out the bowl first, you’ll end up pouring milk on the floor!

In math class, kids learn about HCF and LCM and how to find HCF and LCM. It’s easy to find HCF of two smaller numbers. But with large numbers, this is very difficult! In such cases, you’d have to try many steps. These steps are nothing but an algorithm!

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}