Introduction To Algorithms
Introduction To Algorithms
Introduction To Algorithms
ai Study Material
Spotle.ai/Learn
Introduction
To
Algorithms
How Do You Keep A Software Engineer
Shampooing Forever?
- Lather
- Rinse
- Repeat
A computer executes a
program which is
nothing but a sequence
of codified instructions.
Spotle.ai Study Material
4
Spotle.ai/Learn
What Is An Algorithm?
The sequence of
steps to solve a
specific problem or
attain a specific
goal is called an
algorithm.
Problem Definition
Requirement Analysis
Define Algorithm
Develop Program
Algorithm
PROBLEM -----------> SOLUTION
Input and
Finite
Output
Correct Definite
Effective
Time
Complexity
Space
Complexity
Time complexity of
an algorithm denotes the amount
of time taken by an algorithm to
run, expressed as a function of
the length of the input. Time
complexity actually measures the
number of steps the algorithm
executes rather than the actual
time taken which depends also on
factors like processor speed,
network load etc.
Space Complexity of
an algorithm is
total space taken by
the algorithm as a
function of the input size.
15 Is this 5?
1
2
Say the list in the last 5
(bottom-most number) in 5
7
upper partition. Since 5 < 7,
15
5 will be in the upper
20
partition. Discard lower 22
partition. 100
1
In this algorithm you are 2
halving the input set till you 5 1
have partitions of 1. How 7 2
many times do you have to 15 5
repeat the operation of 20 7
halving the set? 22
100
Let k be the number of times
the set is halved
Then n/2k = 1 or k = log2n 5
7
list? 5 20
7
2nd pass.
Lets designate the first number in 5 is taken
to be smallest;
the list, in this case 20 as the 20
because 5 is
smaller than 20.
smallest number. Compare each 5
5
number in the list with the
7
smallest number. If the number is 3rd pass.
5 stands as the
smaller than the smallest number, smallest;
because 5 is
set smallest number = number. 20 smaller than 7.
5
You are repeating this n=3 times. 5
Choose Most
Convert To Optimal
Code Algorithm