WHAT IS ALGORITHM

WHAT IS ALGORITHM?

ALGORITHM BASICS

    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 upon in order to get the expected results. 



    It can be understood by taking an example of cooking a new recipe. To cook a new recipe, one reads the instructions and steps and execute them one by one, in the given sequence. The result thus obtained is the new dish cooked perfectly. Similarly, algorithms help to do a task in programming to get the expected output. 

    The Algorithm designed 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.


WHAT ARE THE CHARACTERISTICS OF AN ALGORITHM?


As one would not follow any written instructions to cook the recipe, but only the standard one. Similarly, not all written instructions for programming is an algorithm. In order for some instructions to be an algorithm, it must have the following characteristics:


  • Clear and Unambiguous: Algorithm 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 says to take inputs, it should be well-defined inputs.


  • Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well.


  • Finite-ness: The algorithm must be finite, i.e. it should not end up in an infinite loops or similar.


  • Feasible: The algorithm must be simple, generic and practical, such that it can be executed upon will the available resources. It must not contain some future technology, or anything.


  • 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 same, as expected.

ADVANTAGES OF ALGORITHMS:

  • It is easy to understand.

  • Algorithm is a step-wise representation of a solution to a given problem.

  • In 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.

DISADVANTAGES OF ALGORITHMS:

  • Writing an algorithm takes a long time so it is time-consuming.

  • Branching and Looping statements are difficult to show in Algorithms.

HOW TO DESIGN AN ALGORITHM?

In order to write an algorithm, following things are needed as a pre-requisite: 
 

  1. The problem that is to be solved by this algorithm.

  2. The constraints of the problem that must be considered while solving the problem.

  3. The input to be taken to solve the problem.

  4. The output to be expected when the problem the is solved.

  5. The solution to this problem, in the given constraints.


EXAMPLE


Let's try to learn algorithm-writing by using an example.


Problem 1 − Design an algorithm to add two numbers and display the result.


Step 1 − START

Step 2 − declare three integers a, b & c

Step 3 − define values of a & b

Step 4 − add values of a & b

Step 5 − store output of step 4 to c

Step 6 − print c

Step 7 − STOP


Problem 2 − Write an algorithm for simple interest

Step 1 : START 

Step 2: Declare variables  P, R, N  and  I .

Step 3: Read the values of variable  P ( principal amount ) , R ( Rate of Interest ), N ( Number of years ) .

Step 4: calculate the values of  “ I = ( P * R * N )/100 “ .

Step 5: Display I ( simple interest ) .

Step 6: STOP

Popular posts from this blog

DATA STRUCTURES-II

DATA STRUCTURES FOR B.TECH

DATA STRUCTURES FOR BCA