0% found this document useful (0 votes)
99 views

Advaned Analysis of Algorithm

1. Algorithm design and analysis is important for understanding problem solving strategies like divide and conquer, greedy methods, and dynamic programming. 2. Asymptotic notations like Big-O, Omega, and Theta are used to represent the time and space complexity of algorithms. 3. Big-O notation describes worst case complexity and provides an upper bound. Omega notation describes best case complexity and provides a lower bound. Theta notation describes average case complexity.

Uploaded by

rafia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Advaned Analysis of Algorithm

1. Algorithm design and analysis is important for understanding problem solving strategies like divide and conquer, greedy methods, and dynamic programming. 2. Asymptotic notations like Big-O, Omega, and Theta are used to represent the time and space complexity of algorithms. 3. Big-O notation describes worst case complexity and provides an upper bound. Omega notation describes best case complexity and provides a lower bound. Theta notation describes average case complexity.

Uploaded by

rafia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Why Study -> Algorithm Design and Analysis

• It is basically an analytical and Conceptual Subject


• After this, Student will be able to select an appropriate
problem solving strategies for real world:
– Divide and Conquer
– Greedy Method
– Dynamic Programming
• Important for all branches of CSE/IT subjects
– Computer Architecture
– Machine Learning
– Neural Networks
• Play key role in modern technological innovation:
– Robotics
• Time Complexity and Space Complexity
• Optimization of an Algorithm is the purpose of this
course
An Algorithm can be converted
into function
• Problem: Find the smallest element in an array
• Algorithm:
– Step 1: Set min = A[0] 1

– 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

Advanced Analysis of Algorithms


Asymptotic Notations
• Asymptotic Notations are the expressions that are
used to represent the complexity of an algorithm.
• There are three types of analysis that we perform
on a particular algorithm:
– Best Case: In which we analyse the performance of an
algorithm for the input, for which the algorithm takes
less time or space.
– Worst Case: In which we analyse the performance of an
algorithm for the input, for which the algorithm takes
long time or space.
– Average Case: In which we analyse the performance of
an algorithm for the input, for which the algorithm
takes time or space that lies between best and worst
case.
Types of Data Structure
Asymptotic Notation
1. Big-O Notation (Ο) – Big O notation
specifically describes worst case scenario.
2. Omega Notation (Ω) – Omega(Ω) notation
specifically describes best case scenario.
3. Theta Notation (θ) – This notation
represents the average complexity of an
algorithm.
Big-O Notation (Ο)
• Big O notation specifically describes worst
case scenario. It represents the upper bound
running time complexity of an algorithm.
Lets take few examples to understand how
we represent the time and space complexity
using Big O notation.
Examples of Big-O Notation
• O(1)
• Big O notation O(1) represents the complexity of an
algorithm that always execute in same time or space
regardless of the input data.
• O(1) example
The following step will always execute in same
time(or space) regardless of the size of input data.
• Accessing array index(int num = arr[5])
• O(n)
• Big O notation O(n) represents the complexity of an
algorithm, whose performance will grow linearly (in
direct proportion) to the size of the input data.
Examples of Big-O Notation
• O(n) example
The execution time will depend on the size of
array. When the size of the array increases, the
execution time will also increase in the same
proportion (linearly)
• Big O notation O(n2) represents the complexity
of an algorithm, whose performance is directly
proportional to the square of the size of the
input data.
• O(n2) example
– Traversing a 2D array
Other Big O notations
• There are other Big O notations such as:
logarithmic growth O(log n), log-linear
growth O(n log n), exponential growth O(2n)
and factorial growth O(n!).
Other Big-O 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/

You might also like