Advaned Analysis of Algorithm
Advaned Analysis of Algorithm
– Step 2: MinIndex = 0 1
n-1
– Step 3: for (i=1 to n-1)
If (A[j]<A[MinIndex]) Set MinIndex=i
– Step 4: return MinIndex 1
(n-1)+3=n+2
An Algorithm can be converted
into function
• f(n)= n+2
• f(n)= n-1 Linear Function
– Quadratic
– Logarithmic
– Cubic Time
Number of (Machine)
Problem Algorithm Executes Instructions executed
(Function) Space
Use of RAM
Time Complexity: It is a function the time on the algorithm takes in terms of amount
of input to an algorithm.
Lecture # 2
Asymptotic Notations
O(1) < O(log n) < O (n) < O(n log n) < O(n2) < O (n3)< O(2n) < O(n!)
Revision of Logarithm
logarithm
a logarithm is the “power” to which a number must be raised
in order to “get” some other number. The two most common
logarithms are base 10 logarithms (the base unit is the
number being “raised to a power”) and natural logarithms.
logarithm, base ten
a base ten logarithm is the exponent of 10 required for the
expression to equal some other number. It is usually written
in this form: log a=r, which means that a=10r.
logarithm, natural
a natural logarithm is the exponent of e ~ 2.71828183
required for the expression to equal some other number. e is
a transcendental number, which means it does not end. It is
usually written in this form: ln a=r, which means that a=er.
Logarithm
• log a=r is the equivalent to br = a .
b
Examples
a)
• log 1000 = 3
because
• 103 = 1000
b)
• log2 8 = 3
because
• 23 = 8
c)
• What is the log of 4?
• log 4 = x
• log 4 ≈ 0.602
• because
• 10 0.602 ≈ 4
Logarithm
• log (Pt) = t * log P means that the logarithm of
a number raised to some power, it is the same
as multiplying the logarithm of that number by
the value of the power.
For example:
• log (32) = 2 * log 3
• 2 * 0.477 = 0.954
• Considering the concepts of Logarithm
• Give Examples of following expressions:
– logarithmic growth O(log n)
– log-linear growth O(n log n)
Omega Notation (Ω)
• Omega notation specifically describes best
case scenario. It represents the lower bound
running time complexity of an algorithm. So
if we represent a complexity of an algorithm
in Omega notation, it means that
the algorithm cannot be completed in
less time than this, it would at-least take
the time represented by Omega notation or
it can take more (when not in best case
scenario).
Omega Notation (Ω)
Theta Notation (θ)
• This notation describes both upper bound
and lower bound of an algorithm so we can
say that it defines exact asymptotic
behavior.
• In the real case scenario the algorithm not
always run on best and worst cases, the
average running time lies between best and
worst and can be represented by the theta
notation.
Theta Notation (θ)
References:
• https://beginnersbook.com/2018/10/ds-
asymptotic-notation/