maxtek IoT

Algorithm

There are some few words you come across when you start learning any programming languages.

An algorithm is a strictly defined finite sequence of well-defined instructions that provides the solution to a problem. In other words, an algorithm is a step-by-step procedure to solve a given problem. The term “finite” means that the algorithm should reach an end point and cannot run forever.

You can find algorithms everywhere in your real life, not just in progrogramming. For instance, the process for preparing a cup of milk can be expressed as an algorithm. Certain steps, in a certain order, must be followed in order to achieve your goal.

Here is the algorithm for making a cup of milk

  1. Put the powder milk in a cup.
  2. Fill the kettle with water.
  3. Boil the water in the kettle.
  4. Pour some of the boiled water into the cup.
  5. Add sugar to the cup.
  6. Stir the milk.
  7. Drink the milk.

However,if you are like me who does not drink milk, let us jot down the algorithm to add two numbers X and Y.

  1. declare a variable X.
  2. declare a variable Y.
  3. declare a variable Z.
  4. Z=X+Y.

You should not worry about the notation X, Y and Z.They are just alphabet used in discrete mathematics. In real live scenario, a finite value is store in the variable which is out of the scope of this session.

The Three Main Stages Involved in Creating an Algorithm
Three main stages are involved in creating an algorithm: data input, data processing, and results output. The order is specific and cannot be changed. Consider a computer program that finds the average value of three numbers. First, the program must prompt the user to enter the numbers (data input). Next, the program calculates the average value of the numbers (data processing). Finally, the program displays the result on the computer’s screen (results output).
  1. Prompt the user to enter a number.
  2. Prompt the user to enter a second number.
  3. Prompt the user to enter a third number.
  4. Calculate the sum of the three numbers.
  5. Divide the sum by 3.
  6. Display the result on the screen.

From stept 1 to 3 represent data inputs
From step 4 to 5 represent data process
Step 6 represents data output

In a nutshell, solving a programming problem is easy. The only tool you need is your thinking pattern to write the correct algorithm.