Introduction to Algorithms
What is an algorithm ?
The word Algorithm means ” A set of rules to be
followed in calculations or other problem-solving
operations ” Or ” A procedure for solving a
mathematical problem in a finite number of steps
frequently by recursive operations “. Therefore
Algorithm refers to a sequence of finite steps to solve a
particular problem.
Algorithms can be simple and complex depending on
what you want to achieve.
We need to pick the “BEST” algorithm
There can be multiple ways to solve a problem, but we
want to minimize some criteria in the procedure :
1. Time required to solve the problem (Time
complexity)
2. Extra space required to solve the problem (Space
complexity)
How Time complexity is measured
Consider a job :
, Given a square plot of land with side = ‘a’, we need to
buy fencing material to block animals from coming
in.Also, we need to buy fertilizers for the total land
area.
Amount of fencing required
For a square plot of side = ‘a’, the perimeter is = 4a.
Amount of fertilizer required
For a square plot of side = ‘a’, the area is =
a 2.
What is an algorithm ?
The word Algorithm means ” A set of rules to be
followed in calculations or other problem-solving
operations ” Or ” A procedure for solving a
mathematical problem in a finite number of steps
frequently by recursive operations “. Therefore
Algorithm refers to a sequence of finite steps to solve a
particular problem.
Algorithms can be simple and complex depending on
what you want to achieve.
We need to pick the “BEST” algorithm
There can be multiple ways to solve a problem, but we
want to minimize some criteria in the procedure :
1. Time required to solve the problem (Time
complexity)
2. Extra space required to solve the problem (Space
complexity)
How Time complexity is measured
Consider a job :
, Given a square plot of land with side = ‘a’, we need to
buy fencing material to block animals from coming
in.Also, we need to buy fertilizers for the total land
area.
Amount of fencing required
For a square plot of side = ‘a’, the perimeter is = 4a.
Amount of fertilizer required
For a square plot of side = ‘a’, the area is =
a 2.