What is Algorithm | How to write Algorithm

Algorithm :
   To analyze a mathematical problem or data step by step in such a way that it becomes accessible to the computer and the computer can present the appropriate solution to the mathematical problem by taking the available data in the program; is called an algorithm. In fact, in order to get the desired result from the data, the computer can accept it in the processed form.

   Whenever we plan to do any work in our life, we plan its outline in our mind. This outline is also prepared on paper for specific tasks, different stages, how the work will start, when and where it will start, how it will be completed and how it will be completed.

   Similarly, if any task is given to do on the computer, then the programmer has to prepare its complete outline and in which order instructions will be given to get the work done without mistake from the computer. That is, to complete a task one has to go through various stages. When the solution of a problem is written in sequence with different steps, then it is called algorithm. The input data is not necessary for the algorithm, whereas it is expected to arrive at a single result. The instructions given in it should be understandable.

   We have to be very careful in getting any work done from the computer. Because when a person does any work, he has prior experience, the ability to make decisions by thinking and discretion, whereas the computer does not have all this, it works only on the basis of the information received. Therefore, only necessary and true facts should be made available to the computer to do any work. When the algorithm is diagrammed with symbols, the diagram is called a sequential or flow table. The program is prepared on the basis of this sequence guide or flow table.

  1. First put water in a vessel and heat it.
  2. Add tea leaves, sugar and milk to the water.
  3. Wait till the tea boils. Switch off the gas and filter the tea.
  4. The tea is ready now you can drink it.

Before writing an algorithm remember this point:
  1. All the instructions given in the algorithm should be correct and of clear meaning.
  2. Every instruction should be such that it can be complied with in a given time.
  3. There should not be any one or many instructions which are repeated till the end. Ensure that the algorithm finally terminates.
  4. After following all the instructions, the desired result must be obtained at the conclusion of the algorithm.
  5. If the order of any instruction is changed or any instruction is left behind, the desired result will not be obtained at the end of the algorithm.

How to write algorithm:
   Suppose you are given an algorithm to find the sum of all numbers between 1 and 50. It will become as follows:-
step 1: B=2
step 2: print B
step 3: B=B+2
step 4: if B<=50 goto step 2
step 5: if B>50
step 6: stop
Previous Post Next Post