An algorithm is a set of ordered steps or procedures necessary to solve a particular problem. An algorithm must be unambiguous and clear starting and stopping point. It is the verbal form of a program and independent of programming language. Each step in an algorithm tells what task is to be performed.
Example: An algorithm to find the area of a rectangle.
Step 1: Start
Step 2: Declare variables length, breadth, and area.
Step 3: Accept the length of the rectangle.
Step 4: Accept the breadth of the rectangle.
Step 5: Multiply the length and breadth of the rectangle and assign it to a variable area.
Step 6: Display the area of a rectangle.
Step 7: Stop.
Guideline for an algorithm development
- Use Plain Language.
- Don’t use any programming language specific syntax because same algorithm can be implemented using any programming language.
- Every job to be done should be described clearly without any assumptions.
- It must have single entry and exit point.
An excellent algorithm should have the following properties
- Finiteness – Should have finite number of steps to solve the problem.
- Definite – Action of each step should be defined clearly without any ambiguity.
- Inputs – Input should be defined precisely.
- Outputs – Each algorith should result in one or more outputs.
- Effectiveness – It should be more effective among the different ways of solving the problem.
Q. Write an algorithm to find the sum of natural numbers up to the number entered by the user.
Solution :
Step 1: Start
Step 2: Declare variables number, i, sum.
Step 3: Initialize variable i = 1 and sum = 0.
Step 4: Read the positive number from the user.
Step 5: Repeat step 5 until i <= number.
. Step 5.1: sum = sum + i
. Step 5.2: i = i+1
Step 6: Display sum.
Step 7: Stop.