Algorithm
Example 1
Step 1: Start
Step 2: Input first number as P
Step 3: Input second number as Q
Step 3: Set Sum=P+Q
Step 5: Print Sum
Step 6: End.
• An algorithm is a strictly defined finite sequence of
well defined statements (often called instructions or
commands) that provide the solution to a problem or
to a specific class of problems for any acceptable set of
input values (if there are any inputs).
• In other words, an algorithm is a step-by-step
procedure to solve a given problem.
• The term “finite” means that the algorithm should
reach an end point and cannot run forever.
An algorithm must satisfy the following properties:
• Input: The algorithm must have input values from a
specified set.
• Output: The algorithm must produce the output
values from a specified set of input values. The output
values are the solution to a problem.
• Finiteness: For any input, the algorithm must
terminate after a finite number of steps.
• Definiteness: All steps of the algorithm must be
precisely defined.
• Effectiveness: It must be possible to perform each
step of the algorithm correctly and in a finite amount
of time. That is, its steps must be basic enough. It is not
enough that each step is definite (or precisely defined),
but it must also be feasible.
Example 2
Step 1: Start
Step 2: Input value of first number in P
Step 3: Input value of second number in Q
Step 4: Set Temp = P
Step 5: Set P = Q
Step 6: Set Q= Temp
Step 7: Print P and Q
Step 8: End.