Algorithm
Algorithm means ” A set of finite rules or instructions to be followed in calculations or other
problem-solving operations.
An algorithm is a well-defined sequence of steps or instructions designed to solve a specific
problem or perform a particular task.
Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined
inputs. It may or may not take input.
Well-Defined Outputs: The algorithm must clearly define what output will be
yielded and it should be well-defined as well. It should produce at least 1 output.
Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.
Feasible: The algorithm must be simple, generic, and practical, such that it can be
executed with the available resources. It must not contain some future technology or
anything.
Language Independent: The Algorithm designed must be language-independent, i.e.
it must be just plain instructions that can be implemented in any language, and yet the
output will be the same, as expected.
Representation of an Algorithm Flowcharts and pseudocode are two common methods for
representing algorithms.
Flowchart:- A flowchart is a graphical representation of an algorithm. It is easier to
understand than Natural Language. Flowcharts have their use cases in various fields such as
software development, business process modelling, and engineering.
Symbols Used In Flowchart
Descrip
Symbol Purpose
tion
Indicate
s the
flow of
logic by
Flow line
connect
ing
symbol
s.
Represe
nts the
start
Terminal(S
and the
top/Start)
end of a
flowcha
rt.
Used
for
input
Input/
and
Output
output
operati
on.
Used
for
arithme
tic
Processing operati
ons and
data-
manipu
lations.
Used
for
decisio
n
making
Decision
betwee
n two
or more
alternat
ives.
o Arrows (Flowlines): Indicate the direction of flow.
o Oval (Terminal): Represents the start or end of the algorithm.
o Parallelogram (Input/Output): Represents inputting data or outputting
results.
o Rectangle (Process): Represents a processing step or action.
o Diamond (Decision): Represents a point where a decision is made, with
multiple paths based on the outcome.
Algorithm to Add [Sum] of two numbers.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
Step 6: Stop
Pseudocode
Pseudo Code:- Pseudocode is language-independent description of an algorithm that
combines elements of programming languages with natural language. Here we express the
Algorithm in the form of annotations and informative text written in plain English which is
very much similar to the real code but as it has no syntax like any of the programming
languages, it can’t be compiled or interpreted by the computer.
Characteristics:
o Uses keywords like BEGIN, END, READ, PRINT, IF-THEN-
ELSE, FOR, WHILE.
o Emphasizes readability and clarity.
o Indentation is used to show structure and hierarchy.
Example (Pseudocode for calculating the sum of two numbers):
BEGIN
READ Num1
READ Num2
CALCULATE Sum = Num1 + Num2
PRINT Sum
END