Saturday, 4 August 2012

Lesson 1: Algorithm

Algorithm
Its representation of a program logic in the simple and understandable format
its an order sequence of a well-define and unambiguous instructions which perform some task and halt at finite time.
  1. Total number of steps used in algorithm should be finite 
  2. It should halt at finite time
  3. Instructions must be clear and unambiguous
  4. The algorithm should have zero or more input but at-least have one output
  5. Every step must be basic & essential
Categories: Algorithm operations are ordered sequence runs in order like first,second,third instructions. however the one who alter the sequence of instruction is called control structure.
There are three types of algorithm operations.
  • Sequential operations:- In this instruction are executed in sequence
  • Branching/conditional operation:-It is control structure in which it ask question true/false and act according to the answer.
  • Iterative/looping operation:-It is control structure in which it repeat the execution of block instruction

Examples of algorithm:


1) Sequential operation:
write an algorithm to calculate area of rectangle.
Algorithm
  1. Accept the value of length i.e. L
  2. Accept the value of breadth i.e. B
  3. Calculate area i.e. A=L*B
  4. Print Area i.e. A
  5. Stop procedure
2) Branching/conditional:
write an algorithm to find smallest number out of two number.
Algorithm
  1. Accept two numbers i.e.a,b
  2. Check if a<b? If yes go to Step 3 otherwise go to Step5
  3. Print a is smallest number
  4. Stop procedure
  5. Print b is smallest number
  6. Stop procedure
3) Iterative/Looping operation:
write an algorithm to find out factorial of given number.
Algorithm
  1. Accept N
  2. I=1
  3. FACT=1
  4. FACT=FACT*I
  5. I=I+1
  6. If I<=N go to Step 4
  7. Print FACT
  8. Stop procedure