Wednesday, 5 December 2018

Algorithm & Key features / Characteristics of an Algorithm


Algorithm
  • The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.
  • An algorithm may be defined as a finite sequence of steps each of which is precise, unambiguous and executable in finite time.
  • Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output.
  1. Input :> There are zero or more quantities which are externally supplied.
  2. Output :> At least one quantity is produced.
  3. Definiteness :> Each instruction must be clear and unambiguous.
  4. Finiteness :> If we trace out the instructions of an algorithm, then for all cases the algorithm will terminate after a finite number of steps.
  5. Effectiveness: Every instruction must be sufficiently basic that it can in principle be carried out by a person using only pencil and paper.
 
Key features / Characteristics of an Algorithm
Not all procedures can be called an algorithm. An algorithm should have the following characteristics −
  • Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning.
  • Input − An algorithm should have 0 or more well-defined inputs.
  • Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output.
  • Finiteness − Algorithms must terminate after a finite number of steps.
  • Feasibility − Should be feasible with the available resources.
  • Independent − An algorithm should have step-by-step directions, which should be independent of any programming code.
Example:
1. Write an algorithm to convert the temperature in centigrade to the temperature in Fahrenheit. 
Solution:
Step 1. Read the numeric value of C.
step 2. Calculate F using Formula F= (9/5)*c+32.
Step 3. Write numeric value of F.
Step 4. Stop
2. Write an algorithm to checking whether a number is even or odd.
Solution:
Step 1. Read the given number, say x.
Step 2. Devide x by 2.
Step 3. If the remainder is 1, then print x is odd
Step 4. Otherwise print x is even.
Step 5. Stop.
3. Write an algorithm to find the area of circle.
Solution:
Step 1. Read the value of radius.
Step 2. Calculate area using formula area=3.14*radius*radius.
Step 3. Write the value of area.
Step 4. Stop.

No comments:

Post a Comment