Algorithm is the basic technique used to get the job done or problem solving. So we can say an algorithm is a finite list of instructions, most often used in solving problems or performing tasks.
What is algorithm?
Algorithm is the basic technique used to get the job done or problem solving. So we can say an algorithm is a finite list of instructions, most often used in solving problems or performing tasks.
Example of a real life algorithm (How to order pizza)
What is computer algorithm?
It is a well-defined procedure (set of unambiguous instructions) that allow computer to solve problem. Each and every task performed by computer with the help of algorithm.
Qualities of a good algorithm
Write an algorithm to add two numbers entered by user
Step 1: |
Start |
Step 2: |
Declare variables num1, num2, sum |
Step 3: |
Read values from num1 and num2 |
Step 4: |
Add num1 and num2 and assign the result to sum Sum =num1+num2 |
Step 5: |
Display sum |
Step 6: |
Stop |
Few rules to design algorithm
Syntax proposal of algorithm writing
An example using syntax
Find greatest common divisor of two numbers
Input : integer a,b
Output: greatest common divisor of a and b
If a=0 then
return b
while b != 0 do
if a > b then
a = a−b
else
b = b−a
return a