You are on page 1of 16

Algorithm Analysis

Ms. UMA. S
Time Space Trade-Off

An algorithm is a finite step-by-step


list of well defined instructions for
solving a particular problem
Complexity of Algorithm

 Itis the function which gives the running


time or space in terms of input size.
 f(x)
 Time Complexity T(n)

 Number of steps require to complete its run for


input size always smaller than T(n).
 n = number of steps
 n < T(n)
Space Complexity
The number of bits required to complete
its run for a input of size n is always <=
s(n)
 Thisboth defines the efficiency of our
algorithm
 Cases – best , worst , averahe
 Three algorithm
 Which is better
Asymptotic notation

Asymptotic means line that tends


to coverage to curve which may
not eventually touch the curve
means
Within the boundary
 Algorithm takes maximum time to run – upper
bound
 Algorithm takes minimum time to run – lower
bound
 T(n)– any value between Upper Bound and Lower
Bound
Three types of Asymptotic Notations

 Big Oh (O) – worst case


 Big Omega (Ω) – Best Case
 Big Theta (Θ) – Average Case
Big Oh

 Running time
 Big Oh says that
 0< =f(n) <= c.g(n) -- 1
 f(n) – larger than n0
c = constant
n > n0
Example
 f(n) = 3n + 2
 g(n) = n
 Then f(n) = O(g(n)) -- 1
 f(n) <= O(g(n))------- 1
 3n + 2 <= c.n
 3n+2 <= 4n n0 > 2
 Constant value = c
 Write and sort an array
 Teacher – executes – on his system – 16 bit computer – is
slow, takes two days.
 Your – system –executes – enough faster – within a second.
 C-- how much time PC takes to run that program
 C – constant for every unique PC
 If time takes O(n) , then multiply by C
 Thisindicates in this PC, this algorithm takes this
time ---c.O(n).
C – Vary
 Big Oh --- upper bound
 Algorithm takes O(n) – maximum time
 Minimum time is not known
 Not much important

You might also like