Algorithm

Definition – What is Algorithm

The term algorithm refers to the procedure of solving a problem by writing down the instruction step by step using natural language and logic. The purpose of using an algorithm is to express a complex problem in an easy way. I computer science, the algorithm is a very helpful concept for teaching programming language to the novice students. Before writing the source code, writing down the problem in algrothm helps to implement the code easily.

Algorithms are the non-technical procedure to solve a problem. We can implement our everyday life task using an algorithm like the steps of making a cup of tea can be expressed in the algorithm. But in computer science, to design algorithm computer programmers follows some steps such as:

  • Defining the problem by an expert
  • Developing the model
  • Specification/features of the algorithm
  • Designing the algorithm
  • Analysis and implementation of the algorithm
  • Documentation preparing etc.

Example of Algorithm

Let’s see an example of a block of an algorithm. The algorithm compares two integer number and determines which is a greater number than another.

SEND "Enter first number: " TO DISPLAY
RECIEVE num1 FROM KEYBOARD
SEND "Enter second number: " TO DISPLAY
RECIEVE num2 FROM KEYBOARD
IF num1 > num2
    THEN
        SEND "The first number is greater than the second" TO DISPLAY

    ELSE
        SEND "The first number is not greater" TO DISPLAY
END

An algorithm can be implemented in many ways. You can express any programming problem like the above. Let’s see how to implement the code using the above algorithm using C Programming language

#include <stdio.h>

int a, b;

int main() {
    printf("Enter first number: ");
    scanf("%d", &a);
    printf("Enter second number: ");
    scanf("%d", &b;);
    if (a>b)
        printf("The first number is greater than the second");

        else
            printf("The first number is not greater"); 
}