UNIT-1
Algoritham
What is an Algorithm?
➢ The word Algorithm means ” A set of finite rules or instructions to be followed in
calculations or other problem-solving operations ”
➢ Or
➢ ” A procedure for solving a mathematical problem in a finite number of steps that
frequently involves recursive operations”.
➢ Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.
➢ That can be understood by taking the example of cooking a new recipe. To cook a
new recipe, one reads the instructions and steps and executes them one by one, in the
given sequence. The result thus obtained is the new dish cooked perfectly.
➢ The Algorithm designed are language-independent, i.e. they are just plain instructions
that can be implemented in any language, and yet the output will be the same, as
expected.
Characteristics of an Algorithm
Algoritham must have the following characteristics:
1|Page
, ➢ Clear and Unambiguous: The algorithm should be clear and 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 take 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.
Properties of Algorithm:
➢ It should terminate after a finite time.
➢ It should produce at least one output.
➢ It should take zero or more input.
➢ It should be deterministic means giving the same output for the same input case.
➢ Every step in the algorithm must be effective i.e. every step should do some work.
Advantages of Algorithms:
➢ It is easy to understand.
➢ An algorithm is a step-wise representation of a solution to a given problem.
➢ In Algorithm the problem is broken down into smaller pieces or steps hence, it is
easier for the programmer to convert it into an actual program.
Disadvantages of Algorithms:
➢ Writing an algorithm takes a long time so it is time-consuming.
➢ Understanding complex logic through algorithms can be very difficult.
➢ Branching and Looping statements are difficult to show in Algorithms(imp).
How to Design an Algorithm?
In order to write an algorithm, the following things are needed as a pre-requisite:
➢ The problem that is to be solved by this algorithm i.e. clear problem definition.
➢ The constraints of the problem must be considered while solving the problem.
2|Page
, ➢ The input to be taken to solve the problem.
➢ The output to be expected when the problem is solved.
➢ The solution to this problem, is within the given constraints.
➢ Then the algorithm is written with the help of the above parameters such that it solves
the problem.
Pseudo code
➢ Pseudo code is a combination of two words: Pseudo and Code. 'Pseudo' means
imitation and 'code' refer to instruction written in the programming language.
➢ Pseudo code is not a real programming code. It is the generic way of describing an
algorithm without using any specific programming language-related
➢ The pseudo code cannot be compiled. It cannot be executed and there are no real
formatting or syntax rules for writing pseudo codes.
➢ It is simply an important step in producing the final code.
Advantages of Pseudo code:
➢ Since, it is language independent, it can be used by most programmers.
➢ It helps to design in plain natural language.
➢ It is easier to develop the program from pseudo code than with a flowchart.
➢ It is easy to translate to the programming language.
➢ Its simple structure and readability makes it easier to modify as well.
Disadvantages of Pseudo code:
➢ It does not provide the visual representation of the program logic.
➢ There are no accepted standards for writing pseudo code.
Flowchart
What is a Flowchart?
➢ Flowchart is a graphical representation of an algorithm.
➢ Programmers often use it as a program-planning tool to solve a problem.
➢ It makes use of symbols which are connected among them to indicate the flow of
information and processing.
➢ The process of drawing a flowchart for an algorithm is known as “flowcharting”.
3|Page
, FLOWCHART SYMBOLS
Name Symbol Purpose
Terminal / The terminator shows where your process begins
Terminator or ends. You can use words like ‘Start’, ‘Begin’,
‘End’ inside the terminator shape to make things
more obvious.
Process / Flowchart process shape is used to represent a
Rectangle process, action step, or operation. While these are
pictured with rectangles. Eg. Aaddition.
Subtraction. Etc
Data (I/O) Denotes Input/Output Operations. This takes the
shape of a parallelogram.
Decision The decision shape is represented as a Diamond. It
is used for decision making. This shape is quite
unique with two arrows coming out of it. One from
the bottom point corresponding to Yes or True and
one from either the right/left point corresponding
to No or False. The arrows should always be
labeled to avoid confusion in the process flow.
Document The document object is a rectangle with a wave-
like base. This shape is used to represent a
Document or Report in a process flow.
Subroutine / Its called a subroutine if you use this object in
Predefined flowcharting a software program. This allows you
Process to write one subroutine/function and call it as often
as you like from anywhere in the code.
The same object is also called a Predefined
Process. This means the flowchart for the
predefined process has to be already drawn, and
you should reference the flowchart for more
information.
←↑→↓
Flow Lines Denotes the direction of logic flow in the program
4|Page
Algoritham
What is an Algorithm?
➢ The word Algorithm means ” A set of finite rules or instructions to be followed in
calculations or other problem-solving operations ”
➢ Or
➢ ” A procedure for solving a mathematical problem in a finite number of steps that
frequently involves recursive operations”.
➢ Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.
➢ That can be understood by taking the example of cooking a new recipe. To cook a
new recipe, one reads the instructions and steps and executes them one by one, in the
given sequence. The result thus obtained is the new dish cooked perfectly.
➢ The Algorithm designed are language-independent, i.e. they are just plain instructions
that can be implemented in any language, and yet the output will be the same, as
expected.
Characteristics of an Algorithm
Algoritham must have the following characteristics:
1|Page
, ➢ Clear and Unambiguous: The algorithm should be clear and 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 take 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.
Properties of Algorithm:
➢ It should terminate after a finite time.
➢ It should produce at least one output.
➢ It should take zero or more input.
➢ It should be deterministic means giving the same output for the same input case.
➢ Every step in the algorithm must be effective i.e. every step should do some work.
Advantages of Algorithms:
➢ It is easy to understand.
➢ An algorithm is a step-wise representation of a solution to a given problem.
➢ In Algorithm the problem is broken down into smaller pieces or steps hence, it is
easier for the programmer to convert it into an actual program.
Disadvantages of Algorithms:
➢ Writing an algorithm takes a long time so it is time-consuming.
➢ Understanding complex logic through algorithms can be very difficult.
➢ Branching and Looping statements are difficult to show in Algorithms(imp).
How to Design an Algorithm?
In order to write an algorithm, the following things are needed as a pre-requisite:
➢ The problem that is to be solved by this algorithm i.e. clear problem definition.
➢ The constraints of the problem must be considered while solving the problem.
2|Page
, ➢ The input to be taken to solve the problem.
➢ The output to be expected when the problem is solved.
➢ The solution to this problem, is within the given constraints.
➢ Then the algorithm is written with the help of the above parameters such that it solves
the problem.
Pseudo code
➢ Pseudo code is a combination of two words: Pseudo and Code. 'Pseudo' means
imitation and 'code' refer to instruction written in the programming language.
➢ Pseudo code is not a real programming code. It is the generic way of describing an
algorithm without using any specific programming language-related
➢ The pseudo code cannot be compiled. It cannot be executed and there are no real
formatting or syntax rules for writing pseudo codes.
➢ It is simply an important step in producing the final code.
Advantages of Pseudo code:
➢ Since, it is language independent, it can be used by most programmers.
➢ It helps to design in plain natural language.
➢ It is easier to develop the program from pseudo code than with a flowchart.
➢ It is easy to translate to the programming language.
➢ Its simple structure and readability makes it easier to modify as well.
Disadvantages of Pseudo code:
➢ It does not provide the visual representation of the program logic.
➢ There are no accepted standards for writing pseudo code.
Flowchart
What is a Flowchart?
➢ Flowchart is a graphical representation of an algorithm.
➢ Programmers often use it as a program-planning tool to solve a problem.
➢ It makes use of symbols which are connected among them to indicate the flow of
information and processing.
➢ The process of drawing a flowchart for an algorithm is known as “flowcharting”.
3|Page
, FLOWCHART SYMBOLS
Name Symbol Purpose
Terminal / The terminator shows where your process begins
Terminator or ends. You can use words like ‘Start’, ‘Begin’,
‘End’ inside the terminator shape to make things
more obvious.
Process / Flowchart process shape is used to represent a
Rectangle process, action step, or operation. While these are
pictured with rectangles. Eg. Aaddition.
Subtraction. Etc
Data (I/O) Denotes Input/Output Operations. This takes the
shape of a parallelogram.
Decision The decision shape is represented as a Diamond. It
is used for decision making. This shape is quite
unique with two arrows coming out of it. One from
the bottom point corresponding to Yes or True and
one from either the right/left point corresponding
to No or False. The arrows should always be
labeled to avoid confusion in the process flow.
Document The document object is a rectangle with a wave-
like base. This shape is used to represent a
Document or Report in a process flow.
Subroutine / Its called a subroutine if you use this object in
Predefined flowcharting a software program. This allows you
Process to write one subroutine/function and call it as often
as you like from anywhere in the code.
The same object is also called a Predefined
Process. This means the flowchart for the
predefined process has to be already drawn, and
you should reference the flowchart for more
information.
←↑→↓
Flow Lines Denotes the direction of logic flow in the program
4|Page