introductiontoalgorithms-201019152415
introductiontoalgorithms-201019152415
Prathibha
Lecturer
Topics
Introduction to Algorithms
Characteristics of an Algorithm
Analysis of Algorithms
Asymptotic Analysis
Introduction to Algorithms
What is Algorithm ?
An algorithm is a finite set of instructions or logic, written in order, to accomplish a
certain predefined task.
Algorithm is not the complete code or program, it is just the core logic(solution) of a
problem, which can be expressed either as an informal high level description
as pseudocode or using a flowchart.
Algorithm is a step-by-step procedure, which defines a set of instructions to be executed
in a certain order to get the desired output.
Algorithms are generally created independent of underlying languages, i.e. an algorithm
can be implemented in more than one programming language.
Characteristics of an Algorithm
An algorithm should have the following characteristics −
Output − An algorithm should have 1 or more well-defined outputs, and should match
the desired output.
1. START
2. Declare 3 integer variables num1, num2 and num3.
3. Take the three numbers, to be added, as inputs in
variables num1, num2, and num3 respectively.
4. Declare an integer variable sum to store the resultant
sum of the 3 numbers.
5. Add the 3 numbers and store the result in the variable
sum.
6. Print the value of variable sum
7. END
Algorithm Analysis
• Efficiency of an algorithm can be analyzed at two different stages,
before implementation and after implementation. They are −
1. A Priori Analysis :
“Priori” means “before”.
Hence Priori analysis means checking the algorithm before its
implementation.
In this, the algorithm is checked when it is written in the form of
theoretical steps. i.e., This is a theoretical analysis of an algorithm.
Efficiency of an algorithm is measured by assuming that all other
factors,
for example, processor speed, are constant and have no effect on the
implementation.
(contd..)
2. A Posterior Analysis :