Introduction to Algorithm

Default Image

Sequential steps to solve a problem is
called algorithm. If steps are fallowed the problem will be solved. If
we have algorithm to solve a specific problem, it will be easy to
convert it into computer programme. An algorithm usually describes about
getting data, processing of data and show results. For example, if we
want to sum two numbers the algorithm will be written as:

  1. Input 1st number into A
  2. Input 2nd number into B
  3. Sum = A + B
  4. Print Sum
  5. End


Control structure in algorithm


Control structures are used in every
computer language, algorithm is not a computer language, so algorithms
also support these control structures. Programming languages have three
types of execution structure.


  • Sequential
  • Selection
  • Iteration

Sequential


In this type of structure all the
instructions are executed sequentially in which they are written. Not a
single statement is skipped in this structure.


Selection


In this structure instruction are
executed or skipped based on given condition. Different checkpoints are
placed in the form of conditions. These conditions are compulsory to get
our required results.


An algorithm to show selection structure is as follows:


IF condition THEN


Instruction-1


ELSE


Instruction-2


END IF


Write an algorithm to find either a number is even or odd.


  1. START
  2. INPUT a number in A
  3. IF A%2 == 0
  4. PRINT number is even
  5. ELSE
  6. PRINT number is odd
  7. END

Iteration


This structure is also known as loop
structure or repetition structure. Conditions are used in this type upon
which instructions are repeated to get our required result.


Given below is the structure of iteration structure:


       LOOP


Set of instructions


END LOOP


Write an algorithm to sum of first N numbers.


  1. START
  2. INPUT a number in N
  3. SET sum = 0
  4. REPEAT step 5 FOR I = 1 to N
  5. SUM = SUM + I
  6. PRINT SUM
  7. END

Read Count: 3 times

Comments

No comments yet.

Leave a Comment