SlideShare a Scribd company logo
1 of 35
Download to read offline
Algorithms
and Data
Structures
Marcin
Sydow
Algorithms and Data Structures
Complexity of Algorithms
Marcin Sydow
Algorithms
and Data
Structures
Marcin
Sydow
Desired Properties of a Good Algorithm
Any good algorithm should satisfy 2 obvious conditions:
1 compute correct (desired) output (for the given problem)
2 be eective (fast)
ad. 1) correctness of algorithm
ad. 2) complexity of algorithm
Complexity of algorithm measures how fast is the algorithm
(time complexity) and what amount of memory it uses
(space complexity) - time and memory - 2 basic resources in
computations
Algorithms
and Data
Structures
Marcin
Sydow
Example - the Search Problem
Problem of searching a key in an array
What does the amount of work of this algorithm depend on?
find(arr, len, key)
Specication:
input: arr - array of integers, len - it's length, key - integer to be found
output: integer 0 ≤ i  len being the index in arr, under which the key is
stored
Algorithms
and Data
Structures
Marcin
Sydow
Example - the Search Problem
Problem of searching a key in an array
What does the amount of work of this algorithm depend on?
find(arr, len, key)
Specication:
input: arr - array of integers, len - it's length, key - integer to be found
output: integer 0 ≤ i  len being the index in arr, under which the key is
stored (is it a complete/clear specication?)
Algorithms
and Data
Structures
Marcin
Sydow
Example - the Search Problem
Problem of searching a key in an array
What does the amount of work of this algorithm depend on?
find(arr, len, key)
Specication:
input: arr - array of integers, len - it's length, key - integer to be found
output: integer 0 ≤ i  len being the index in arr, under which the key is
stored (is it a complete/clear specication?) or the value of -1 when there
is no specied key in (rst len positions of) the array
Algorithms
and Data
Structures
Marcin
Sydow
Example - the Search Problem
Problem of searching a key in an array
What does the amount of work of this algorithm depend on?
find(arr, len, key)
Specication:
input: arr - array of integers, len - it's length, key - integer to be found
output: integer 0 ≤ i  len being the index in arr, under which the key is
stored (is it a complete/clear specication?) or the value of -1 when there
is no specied key in (rst len positions of) the array
code:
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
What does the amount of work of this algorithm depend on?
Algorithms
and Data
Structures
Marcin
Sydow
The speed of algorithm
How to measure how fast (or slow) an algorithm is?
There are 2 issues to be considered when designing such a
measure:
1 independence on any programming language (and
hardware/software platform)
2 maximum independence on particular input data
It should be an internal property of the algorithm itself
Any idea?
Algorithms
and Data
Structures
Marcin
Sydow
The speed of algorithm
How to measure how fast (or slow) an algorithm is?
There are 2 issues to be considered when designing such a
measure:
1 independence on any programming language (and
hardware/software platform)
2 maximum independence on particular input data
It should be an internal property of the algorithm itself
Any idea? Count basic operations of the algorithm
Algorithms
and Data
Structures
Marcin
Sydow
Dominating Operations
Simplication: it is not necessary to count all the operations - it
is enough to count the representative ones
Before doing a complexity analysis 2 steps must be done:
1 determine the dominating operation set
2 observe what (in input) inuences the number of
dominating operations (data size)
Dominating operations are those which cover the amount of
work which is proportional to the whole amount of work of the
algorithm (they well represent the whole)
Algorithms
and Data
Structures
Marcin
Sydow
Example - determining operating operations
What can be the dominating operation set in the following
algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
assignment i = 0 ?
Algorithms
and Data
Structures
Marcin
Sydow
Example - determining operating operations
What can be the dominating operation set in the following
algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
assignment i = 0 ? no
comparison i  len ?
Algorithms
and Data
Structures
Marcin
Sydow
Example - determining operating operations
What can be the dominating operation set in the following
algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
assignment i = 0 ? no
comparison i  len ? yes
comparison arr[i] == key ?
Algorithms
and Data
Structures
Marcin
Sydow
Example - determining operating operations
What can be the dominating operation set in the following
algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
assignment i = 0 ? no
comparison i  len ? yes
comparison arr[i] == key ? yes
both the above?
Algorithms
and Data
Structures
Marcin
Sydow
Example - determining operating operations
What can be the dominating operation set in the following
algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
assignment i = 0 ? no
comparison i  len ? yes
comparison arr[i] == key ? yes
both the above? yes
return statement return i ?
Algorithms
and Data
Structures
Marcin
Sydow
Example - determining operating operations
What can be the dominating operation set in the following
algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
assignment i = 0 ? no
comparison i  len ? yes
comparison arr[i] == key ? yes
both the above? yes
return statement return i ? no
index increment i++ ?
Algorithms
and Data
Structures
Marcin
Sydow
Example - determining operating operations
What can be the dominating operation set in the following
algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
assignment i = 0 ? no
comparison i  len ? yes
comparison arr[i] == key ? yes
both the above? yes
return statement return i ? no
index increment i++ ? yes
Algorithms
and Data
Structures
Marcin
Sydow
Example, cont. - determining the data size
What is the data size in the following algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
Algorithms
and Data
Structures
Marcin
Sydow
Example, cont. - determining the data size
What is the data size in the following algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
Data size: length of array arr
Algorithms
and Data
Structures
Marcin
Sydow
Example, cont. - determining the data size
What is the data size in the following algorithm?
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
Data size: length of array arr
Having determined the dominating operation and data size
we can determine time complexity of the algorithm
Algorithms
and Data
Structures
Marcin
Sydow
Time Complexity of Algorithm
Denition
Time Complexity of Algorithm is the number of dominating
operations executed by the algorithm as the function of data
size.
Time complexity measures the amount of work done by the
algorithm during solving the problem in the way which is
independent on the implementation and particular input data.
The lower time complexity the faster algorithm
Algorithms
and Data
Structures
Marcin
Sydow
Example - time complexity of algorithm
find(arr, len, key){
i = 0
while(i  len){
if(arr[i] == key)
return i
i++
}
return -1
}
Assume:
dominating operation: comparison arr[i] == key
data size: the length of array (denote by n)
Thus, the number of dominating operations executed by this
algorithm ranges:
from 1 (the key was found under the rst index)
to n (the key is absent or under the last index)
There is no single function which could express the dependence of the number of
executed dominating operations on the data size for this algorithm.
Algorithms
and Data
Structures
Marcin
Sydow
Pessimistic Time Complexity
let's assume the following denotations:
n - data size
Dn - the set of all possible input datasets of size n
t(d) - the number of dominating operations for dataset d (of size n)
(d ∈ Dn)
Denition
Pessimistic Time Complexity of algorithm:
W(n) = sup{t(d) : d ∈ Dn}
(W(n) - Worst)
Pessimistic Time Complexity expresses the number of
dominating operations in the worst case of input data of size n
E.g. for our example the pessimistic time complexity is given by
the formula:
Algorithms
and Data
Structures
Marcin
Sydow
Pessimistic Time Complexity
let's assume the following denotations:
n - data size
Dn - the set of all possible input datasets of size n
t(d) - the number of dominating operations for dataset d (of size n)
(d ∈ Dn)
Denition
Pessimistic Time Complexity of algorithm:
W(n) = sup{t(d) : d ∈ Dn}
(W(n) - Worst)
Pessimistic Time Complexity expresses the number of
dominating operations in the worst case of input data of size n
E.g. for our example the pessimistic time complexity is given by
the formula:
W(n) = n
Algorithms
and Data
Structures
Marcin
Sydow
Average Time Complexity of Algorithm
let's assume the following denotations:
n - data size
Dn - the set of all possible input datasets of size n
t(d) - the number of dominating operations for dataset d (of size n) (d ∈ Dn)
Xn - random variable, its value is t(d) for d ∈ Dn
pnk - probability distribution of the random variable Xn (i.e. the probability that
for input data of size n the algorithm will execute k dominating operations
(k ≥ 0))
Denition
Average Time Complexity of Algorithm:
A(n) = k≥0
pnk · k = P(Xn = k) · k
(expected value of the random variable representing the number
of dominating operations)
(A(n) Average)
Algorithms
and Data
Structures
Marcin
Sydow
Example - Determining the Average Time
Complexity
Let's determine the average time complexity for our exemplary
algorithm (nd)
First, we have to assume some probabilistic model of input
data (i.e. the probabilistic distribution of possible input
datasets)
Let's make a simplistic assumption: the key to be found occurs
exactly once in array and with the same probability on each
index (uniform distribution) (∀0≤knP(Xn = k) = 1/n)
Thus:
A(n) = k≥0
P(Xn = k) · k = 0≤kn 1/n · k = n+1
2
Algorithms
and Data
Structures
Marcin
Sydow
Space Complexity of Algorithm
Denition
Space Complexity of Algorithm: S(n) is the number of units
of memory used by algorithm as a function of data size
This characteristic is more dependent on particular platform than time complexity.
As a memory unit one can consider the machine word.
Note:
We will assume, that the memory used for keeping the input
data is not considered because usually arrays (and other
compound types) are passed as arguments to functions by
reference, which does not involve much memory
In our example space complexity is constant - because it consumes memory only
for a single variable (plus some xed number of additional temporal variables),
independently on the input data size: S(n) = const
Algorithms
and Data
Structures
Marcin
Sydow
Omitting Unimportant Details
The real time spent by an implementation of the algorithm
may dier between particular platforms by a constant
multiplicative factor. (e.g. CPU speed)
Thus, it would be very useful to have a notation allowing for
expressing the complexity functions with neglecting
unimportant details (as multiplicative or additive constant, for
example)
E.g. for the following function:
A(n) = 2.1 · n − 1
The most important information is that it is a linear function -
it's rank of complexity is linear
Does such a notation exist?
Algorithms
and Data
Structures
Marcin
Sydow
Asymptotic Notation - Big O
The notation is called asymptotic notation.
There are a couple of avours. The most common is big O:
Denition
The function g(n) is the upper bound of rank of order of the
function f(n):
f (n) = O(g(n)) ⇔ ∃c0∃n0∀n≥n0f (n) ≤ c · g(n)
The O() notation intuitively corresponds to the ≤ symbol (in
terms of ranks of orders of functions).
E.g. the fact that W(n) of our exemplary algorithm has an
upper bound of the linear rank can be noted as:
W(n) = n+1
2
= O(n)
The constant space complexity S(n) of that algorithm can be
expressed with the following special notation:
S(n) = O(1)
Algorithms
and Data
Structures
Marcin
Sydow
Asymptotic Notation - Big Theta
Another important avour of asymptotic notation is big Theta:
Denition
The function f(n) has the same rank of order as the function
g(n): f (n) = Θ(g(n)) ⇔ f (n) = O(g(n)) ∧ g(n) = O(f (n))
The Θ() notation intuitively corresponds to the = symbol (in
terms of ranks of orders of functions).
Notice, that Θ() is dened with the use of O(), similarly as = symbol can be
dened with the use of ≤ symbol.
E.g. the expression: f (n) = n2
+ n − 3 = Θ(n2
)
reads as the n2
+ n − 3 function is of square rank of order.
Algorithms
and Data
Structures
Marcin
Sydow
Other Flavours of Asymptotic Notation
We have 5 relation symbols for comparing numbers: = ≤ ≥  
In total, we also have 5 analogous symbols for comparing ranks
of functions:
1 Θ - =
2 O - ≤
3 Ω - ≥
4 o - 
5 ω - 
(in general, a capital letter denotes non-sharp inequality and lowercase denotes
a sharp one)
E.g.:
W(n)=o(n) (lowercase o)
means: the rank of function W(n) is lower than linear
Algorithms
and Data
Structures
Marcin
Sydow
Some Remarks on Using the Asymptotic Notation
Notice: in expressions like f(n)=O(g(n)) the = has a special
meaning - it does not represent the normal equality. The
expression has it's meaning only as a whole.
E.g. it does not make sense to use asymptotic notation as the
rst expression on the left-hand side of the = symbol.
E.g. expressions like O(f(n)) = n or O(f(n)) = O(g(n)) do
not make any sense
Besides the standard usage of the asymptotic notation on the
right-hand side of the = symbol, it can be also used in the
following way:
f(n) = g(n) + O(h(n))
Which means: f(n) - g(n) = O(h(n))
(the ranks of functions f and g dier at most by a rank of
function h)
Algorithms
and Data
Structures
Marcin
Sydow
Remarks: Comparing Ranks of Functions
Sometimes the following technique is useful.
Ranks of some 2 functions f(n) and g(n) can be compared by
computing the following limit:
limn→∞
f(n)
g(n)
there are 3 possible cases for the limit:
1 ∞ - in that case f(n)=ω(g(n)) (f has higher rank)
2 a positive constant - in that case f(n)=Θ(g(n)) (the same
ranks)
3 zero - in that case f(n)=o(g(n)) (lowercase o) (g has
higher rank)
Algorithms
and Data
Structures
Marcin
Sydow
The Most Common Ranks of Functions
constant (e.g. S(n) = 3 = Θ(1))
logarithmic (e.g. W(n) = 2 + lg2n = Θ(log(n)))
linear (e.g. A(n) = 2n + 1 = Θ(n))
linear-logarithmic (e.g.
A(n) = 1.44 · nlog(n) = Θ(nlog(n)))
square (e.g. W(n) = n2
+ 4 = Θ(n2
))
cubic (e.g. A(n) = Θ(n3
))
sub-exponential (e.g. A(n) = Θ(nlog(n)))
exponential (e.g. A(n) = Θ(2
n))
factorial (e.g. W(n) = Θ(n!))
In simplication: in practise, an over-polynomial rank of time complexity is
considered as unacceptably high
In case of space complexity, even linear rank is considered as very high
Algorithms
and Data
Structures
Marcin
Sydow
Questions/Problems:
How to measure the speed of algorithm
What 2 things should be determined before starting
assessing the time complexity of an algorithm
What is a dominating operation
Denition of Time Complexity of Algorithm
Denition of Space Complexity of Algorithm
Denition of Pessimistic Time Complexity
Denition of Average Time Complexity
Be able to determine time complexity for simple algorithms
What is the purpose of the asymptotic notation
Denition and interpretation of the O() notation
Denitions (and interpretations) of the other types of
asymptotic notations
Ability to express rank of a given function with the
asymptotic notation
Algorithms
and Data
Structures
Marcin
Sydow
Thank you for your attention

More Related Content

What's hot

Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms ManishPrajapati78
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)jehan1987
 
Data structure and algorithm notes
Data structure and algorithm notesData structure and algorithm notes
Data structure and algorithm notessuman khadka
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureVrushali Dhanokar
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
Introduction to datastructure and algorithm
Introduction to datastructure and algorithmIntroduction to datastructure and algorithm
Introduction to datastructure and algorithmPratik Mota
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notationsjayavignesh86
 
Design and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. MohiteDesign and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. MohiteZeal Education Society, Pune
 

What's hot (20)

Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Data structure and algorithm notes
Data structure and algorithm notesData structure and algorithm notes
Data structure and algorithm notes
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Introduction to datastructure and algorithm
Introduction to datastructure and algorithmIntroduction to datastructure and algorithm
Introduction to datastructure and algorithm
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Big o notation
Big o notationBig o notation
Big o notation
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
 
Design and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. MohiteDesign and analysis of Algorithm By Dr. B. J. Mohite
Design and analysis of Algorithm By Dr. B. J. Mohite
 
chapter 1
chapter 1chapter 1
chapter 1
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 

Viewers also liked

03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm propertiesLincoln School
 
Making Static Pivoting Scalable and Dependable
Making Static Pivoting Scalable and DependableMaking Static Pivoting Scalable and Dependable
Making Static Pivoting Scalable and DependableJason Riedy
 
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...leifwalsh
 
Write optimization in external memory data structures
Write optimization in external memory data structuresWrite optimization in external memory data structures
Write optimization in external memory data structuresleifwalsh
 
ESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction Challenge
ESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction ChallengeESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction Challenge
ESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction ChallengeFrancisco Zamora-Martinez
 
Write optimization in external memory data structures
Write optimization in external memory data structuresWrite optimization in external memory data structures
Write optimization in external memory data structuresleifwalsh
 
Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)
Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)
Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)leifwalsh
 
The Language of Compression
The Language of CompressionThe Language of Compression
The Language of Compressionleifwalsh
 
Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...
Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...
Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...Francisco Zamora-Martinez
 
Visualization of large FEM meshes
Visualization of large FEM meshesVisualization of large FEM meshes
Visualization of large FEM meshesTomáš Hnilica
 
Algorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisAlgorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisDhrumil Patel
 
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...
 Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo... Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo...
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...Rogue Wave Software
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithmsrajatmay1992
 
Efficient Viterbi algorithms for lexical tree based models
Efficient Viterbi algorithms for lexical tree based modelsEfficient Viterbi algorithms for lexical tree based models
Efficient Viterbi algorithms for lexical tree based modelsFrancisco Zamora-Martinez
 
qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...
qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...
qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...Sri Ambati
 
Some empirical evaluations of a temperature forecasting module based on Art...
Some empirical evaluations of a temperature forecasting module   based on Art...Some empirical evaluations of a temperature forecasting module   based on Art...
Some empirical evaluations of a temperature forecasting module based on Art...Francisco Zamora-Martinez
 
Write-optimization in external memory data structures (Highload++ 2014)
Write-optimization in external memory data structures (Highload++ 2014)Write-optimization in external memory data structures (Highload++ 2014)
Write-optimization in external memory data structures (Highload++ 2014)leifwalsh
 

Viewers also liked (20)

03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
 
Making Static Pivoting Scalable and Dependable
Making Static Pivoting Scalable and DependableMaking Static Pivoting Scalable and Dependable
Making Static Pivoting Scalable and Dependable
 
@pospaseis
@pospaseis@pospaseis
@pospaseis
 
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
A New MongoDB Sharding Architecture for Higher Availability and Better Resour...
 
Write optimization in external memory data structures
Write optimization in external memory data structuresWrite optimization in external memory data structures
Write optimization in external memory data structures
 
ESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction Challenge
ESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction ChallengeESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction Challenge
ESAI-CEU-UCH solution for American Epilepsy Society Seizure Prediction Challenge
 
Write optimization in external memory data structures
Write optimization in external memory data structuresWrite optimization in external memory data structures
Write optimization in external memory data structures
 
Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)
Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)
Introducing TokuMX: The Performance Engine for MongoDB (NYC.rb 2013-12-10)
 
The Language of Compression
The Language of CompressionThe Language of Compression
The Language of Compression
 
PhD defence
PhD defencePhD defence
PhD defence
 
Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...
Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...
Mejora del reconocimiento de palabras manuscritas aisladas mediante un clasif...
 
Visualization of large FEM meshes
Visualization of large FEM meshesVisualization of large FEM meshes
Visualization of large FEM meshes
 
Algorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisAlgorithms : Introduction and Analysis
Algorithms : Introduction and Analysis
 
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...
 Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo... Debugging Numerical Simulations on Accelerated Architectures  - TotalView fo...
Debugging Numerical Simulations on Accelerated Architectures - TotalView fo...
 
Efficient Sorts
Efficient SortsEfficient Sorts
Efficient Sorts
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
 
Efficient Viterbi algorithms for lexical tree based models
Efficient Viterbi algorithms for lexical tree based modelsEfficient Viterbi algorithms for lexical tree based models
Efficient Viterbi algorithms for lexical tree based models
 
qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...
qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...
qconsf 2013: Top 10 Performance Gotchas for scaling in-memory Algorithms - Sr...
 
Some empirical evaluations of a temperature forecasting module based on Art...
Some empirical evaluations of a temperature forecasting module   based on Art...Some empirical evaluations of a temperature forecasting module   based on Art...
Some empirical evaluations of a temperature forecasting module based on Art...
 
Write-optimization in external memory data structures (Highload++ 2014)
Write-optimization in external memory data structures (Highload++ 2014)Write-optimization in external memory data structures (Highload++ 2014)
Write-optimization in external memory data structures (Highload++ 2014)
 

Similar to Algorithem complexity in data sructure

Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 DsQundeel
 
Data Structure
Data StructureData Structure
Data Structuresheraz1
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 DsQundeel
 
Algorithms Intro Lecture
Algorithms Intro LectureAlgorithms Intro Lecture
Algorithms Intro LectureIra D
 
Advanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfAdvanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfSheba41
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0BG Java EE Course
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notationirdginfo
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence RelationNilaNila16
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureRai University
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureRai University
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptxEnosSalar
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Ra'Fat Al-Msie'deen
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptxrajesshs31r
 

Similar to Algorithem complexity in data sructure (20)

Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Data Structure
Data StructureData Structure
Data Structure
 
Lec 1 Ds
Lec 1 DsLec 1 Ds
Lec 1 Ds
 
Algorithms Intro Lecture
Algorithms Intro LectureAlgorithms Intro Lecture
Algorithms Intro Lecture
 
Advanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfAdvanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdf
 
Cis435 week01
Cis435 week01Cis435 week01
Cis435 week01
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence Relation
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structure
 
Searching.pptx
Searching.pptxSearching.pptx
Searching.pptx
 
Chapter two
Chapter twoChapter two
Chapter two
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptx
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
 
Chapter one
Chapter oneChapter one
Chapter one
 
Algorithms
Algorithms Algorithms
Algorithms
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 

More from Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devicesKumar
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithmsKumar
 
region-filling
region-fillingregion-filling
region-fillingKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xsltKumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xmlKumar
 
Xml basics
Xml basicsXml basics
Xml basicsKumar
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xmlKumar
 
Applying xml
Applying xmlApplying xml
Applying xmlKumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLKumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB FundmentalsKumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programmingKumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EEKumar
 

More from Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
region-filling
region-fillingregion-filling
region-filling
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 

Algorithem complexity in data sructure

  • 1. Algorithms and Data Structures Marcin Sydow Algorithms and Data Structures Complexity of Algorithms Marcin Sydow
  • 2. Algorithms and Data Structures Marcin Sydow Desired Properties of a Good Algorithm Any good algorithm should satisfy 2 obvious conditions: 1 compute correct (desired) output (for the given problem) 2 be eective (fast) ad. 1) correctness of algorithm ad. 2) complexity of algorithm Complexity of algorithm measures how fast is the algorithm (time complexity) and what amount of memory it uses (space complexity) - time and memory - 2 basic resources in computations
  • 3. Algorithms and Data Structures Marcin Sydow Example - the Search Problem Problem of searching a key in an array What does the amount of work of this algorithm depend on? find(arr, len, key) Specication: input: arr - array of integers, len - it's length, key - integer to be found output: integer 0 ≤ i len being the index in arr, under which the key is stored
  • 4. Algorithms and Data Structures Marcin Sydow Example - the Search Problem Problem of searching a key in an array What does the amount of work of this algorithm depend on? find(arr, len, key) Specication: input: arr - array of integers, len - it's length, key - integer to be found output: integer 0 ≤ i len being the index in arr, under which the key is stored (is it a complete/clear specication?)
  • 5. Algorithms and Data Structures Marcin Sydow Example - the Search Problem Problem of searching a key in an array What does the amount of work of this algorithm depend on? find(arr, len, key) Specication: input: arr - array of integers, len - it's length, key - integer to be found output: integer 0 ≤ i len being the index in arr, under which the key is stored (is it a complete/clear specication?) or the value of -1 when there is no specied key in (rst len positions of) the array
  • 6. Algorithms and Data Structures Marcin Sydow Example - the Search Problem Problem of searching a key in an array What does the amount of work of this algorithm depend on? find(arr, len, key) Specication: input: arr - array of integers, len - it's length, key - integer to be found output: integer 0 ≤ i len being the index in arr, under which the key is stored (is it a complete/clear specication?) or the value of -1 when there is no specied key in (rst len positions of) the array code: find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } What does the amount of work of this algorithm depend on?
  • 7. Algorithms and Data Structures Marcin Sydow The speed of algorithm How to measure how fast (or slow) an algorithm is? There are 2 issues to be considered when designing such a measure: 1 independence on any programming language (and hardware/software platform) 2 maximum independence on particular input data It should be an internal property of the algorithm itself Any idea?
  • 8. Algorithms and Data Structures Marcin Sydow The speed of algorithm How to measure how fast (or slow) an algorithm is? There are 2 issues to be considered when designing such a measure: 1 independence on any programming language (and hardware/software platform) 2 maximum independence on particular input data It should be an internal property of the algorithm itself Any idea? Count basic operations of the algorithm
  • 9. Algorithms and Data Structures Marcin Sydow Dominating Operations Simplication: it is not necessary to count all the operations - it is enough to count the representative ones Before doing a complexity analysis 2 steps must be done: 1 determine the dominating operation set 2 observe what (in input) inuences the number of dominating operations (data size) Dominating operations are those which cover the amount of work which is proportional to the whole amount of work of the algorithm (they well represent the whole)
  • 10. Algorithms and Data Structures Marcin Sydow Example - determining operating operations What can be the dominating operation set in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } assignment i = 0 ?
  • 11. Algorithms and Data Structures Marcin Sydow Example - determining operating operations What can be the dominating operation set in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } assignment i = 0 ? no comparison i len ?
  • 12. Algorithms and Data Structures Marcin Sydow Example - determining operating operations What can be the dominating operation set in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } assignment i = 0 ? no comparison i len ? yes comparison arr[i] == key ?
  • 13. Algorithms and Data Structures Marcin Sydow Example - determining operating operations What can be the dominating operation set in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } assignment i = 0 ? no comparison i len ? yes comparison arr[i] == key ? yes both the above?
  • 14. Algorithms and Data Structures Marcin Sydow Example - determining operating operations What can be the dominating operation set in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } assignment i = 0 ? no comparison i len ? yes comparison arr[i] == key ? yes both the above? yes return statement return i ?
  • 15. Algorithms and Data Structures Marcin Sydow Example - determining operating operations What can be the dominating operation set in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } assignment i = 0 ? no comparison i len ? yes comparison arr[i] == key ? yes both the above? yes return statement return i ? no index increment i++ ?
  • 16. Algorithms and Data Structures Marcin Sydow Example - determining operating operations What can be the dominating operation set in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } assignment i = 0 ? no comparison i len ? yes comparison arr[i] == key ? yes both the above? yes return statement return i ? no index increment i++ ? yes
  • 17. Algorithms and Data Structures Marcin Sydow Example, cont. - determining the data size What is the data size in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 }
  • 18. Algorithms and Data Structures Marcin Sydow Example, cont. - determining the data size What is the data size in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } Data size: length of array arr
  • 19. Algorithms and Data Structures Marcin Sydow Example, cont. - determining the data size What is the data size in the following algorithm? find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } Data size: length of array arr Having determined the dominating operation and data size we can determine time complexity of the algorithm
  • 20. Algorithms and Data Structures Marcin Sydow Time Complexity of Algorithm Denition Time Complexity of Algorithm is the number of dominating operations executed by the algorithm as the function of data size. Time complexity measures the amount of work done by the algorithm during solving the problem in the way which is independent on the implementation and particular input data. The lower time complexity the faster algorithm
  • 21. Algorithms and Data Structures Marcin Sydow Example - time complexity of algorithm find(arr, len, key){ i = 0 while(i len){ if(arr[i] == key) return i i++ } return -1 } Assume: dominating operation: comparison arr[i] == key data size: the length of array (denote by n) Thus, the number of dominating operations executed by this algorithm ranges: from 1 (the key was found under the rst index) to n (the key is absent or under the last index) There is no single function which could express the dependence of the number of executed dominating operations on the data size for this algorithm.
  • 22. Algorithms and Data Structures Marcin Sydow Pessimistic Time Complexity let's assume the following denotations: n - data size Dn - the set of all possible input datasets of size n t(d) - the number of dominating operations for dataset d (of size n) (d ∈ Dn) Denition Pessimistic Time Complexity of algorithm: W(n) = sup{t(d) : d ∈ Dn} (W(n) - Worst) Pessimistic Time Complexity expresses the number of dominating operations in the worst case of input data of size n E.g. for our example the pessimistic time complexity is given by the formula:
  • 23. Algorithms and Data Structures Marcin Sydow Pessimistic Time Complexity let's assume the following denotations: n - data size Dn - the set of all possible input datasets of size n t(d) - the number of dominating operations for dataset d (of size n) (d ∈ Dn) Denition Pessimistic Time Complexity of algorithm: W(n) = sup{t(d) : d ∈ Dn} (W(n) - Worst) Pessimistic Time Complexity expresses the number of dominating operations in the worst case of input data of size n E.g. for our example the pessimistic time complexity is given by the formula: W(n) = n
  • 24. Algorithms and Data Structures Marcin Sydow Average Time Complexity of Algorithm let's assume the following denotations: n - data size Dn - the set of all possible input datasets of size n t(d) - the number of dominating operations for dataset d (of size n) (d ∈ Dn) Xn - random variable, its value is t(d) for d ∈ Dn pnk - probability distribution of the random variable Xn (i.e. the probability that for input data of size n the algorithm will execute k dominating operations (k ≥ 0)) Denition Average Time Complexity of Algorithm: A(n) = k≥0 pnk · k = P(Xn = k) · k (expected value of the random variable representing the number of dominating operations) (A(n) Average)
  • 25. Algorithms and Data Structures Marcin Sydow Example - Determining the Average Time Complexity Let's determine the average time complexity for our exemplary algorithm (nd) First, we have to assume some probabilistic model of input data (i.e. the probabilistic distribution of possible input datasets) Let's make a simplistic assumption: the key to be found occurs exactly once in array and with the same probability on each index (uniform distribution) (∀0≤knP(Xn = k) = 1/n) Thus: A(n) = k≥0 P(Xn = k) · k = 0≤kn 1/n · k = n+1 2
  • 26. Algorithms and Data Structures Marcin Sydow Space Complexity of Algorithm Denition Space Complexity of Algorithm: S(n) is the number of units of memory used by algorithm as a function of data size This characteristic is more dependent on particular platform than time complexity. As a memory unit one can consider the machine word. Note: We will assume, that the memory used for keeping the input data is not considered because usually arrays (and other compound types) are passed as arguments to functions by reference, which does not involve much memory In our example space complexity is constant - because it consumes memory only for a single variable (plus some xed number of additional temporal variables), independently on the input data size: S(n) = const
  • 27. Algorithms and Data Structures Marcin Sydow Omitting Unimportant Details The real time spent by an implementation of the algorithm may dier between particular platforms by a constant multiplicative factor. (e.g. CPU speed) Thus, it would be very useful to have a notation allowing for expressing the complexity functions with neglecting unimportant details (as multiplicative or additive constant, for example) E.g. for the following function: A(n) = 2.1 · n − 1 The most important information is that it is a linear function - it's rank of complexity is linear Does such a notation exist?
  • 28. Algorithms and Data Structures Marcin Sydow Asymptotic Notation - Big O The notation is called asymptotic notation. There are a couple of avours. The most common is big O: Denition The function g(n) is the upper bound of rank of order of the function f(n): f (n) = O(g(n)) ⇔ ∃c0∃n0∀n≥n0f (n) ≤ c · g(n) The O() notation intuitively corresponds to the ≤ symbol (in terms of ranks of orders of functions). E.g. the fact that W(n) of our exemplary algorithm has an upper bound of the linear rank can be noted as: W(n) = n+1 2 = O(n) The constant space complexity S(n) of that algorithm can be expressed with the following special notation: S(n) = O(1)
  • 29. Algorithms and Data Structures Marcin Sydow Asymptotic Notation - Big Theta Another important avour of asymptotic notation is big Theta: Denition The function f(n) has the same rank of order as the function g(n): f (n) = Θ(g(n)) ⇔ f (n) = O(g(n)) ∧ g(n) = O(f (n)) The Θ() notation intuitively corresponds to the = symbol (in terms of ranks of orders of functions). Notice, that Θ() is dened with the use of O(), similarly as = symbol can be dened with the use of ≤ symbol. E.g. the expression: f (n) = n2 + n − 3 = Θ(n2 ) reads as the n2 + n − 3 function is of square rank of order.
  • 30. Algorithms and Data Structures Marcin Sydow Other Flavours of Asymptotic Notation We have 5 relation symbols for comparing numbers: = ≤ ≥ In total, we also have 5 analogous symbols for comparing ranks of functions: 1 Θ - = 2 O - ≤ 3 Ω - ≥ 4 o - 5 ω - (in general, a capital letter denotes non-sharp inequality and lowercase denotes a sharp one) E.g.: W(n)=o(n) (lowercase o) means: the rank of function W(n) is lower than linear
  • 31. Algorithms and Data Structures Marcin Sydow Some Remarks on Using the Asymptotic Notation Notice: in expressions like f(n)=O(g(n)) the = has a special meaning - it does not represent the normal equality. The expression has it's meaning only as a whole. E.g. it does not make sense to use asymptotic notation as the rst expression on the left-hand side of the = symbol. E.g. expressions like O(f(n)) = n or O(f(n)) = O(g(n)) do not make any sense Besides the standard usage of the asymptotic notation on the right-hand side of the = symbol, it can be also used in the following way: f(n) = g(n) + O(h(n)) Which means: f(n) - g(n) = O(h(n)) (the ranks of functions f and g dier at most by a rank of function h)
  • 32. Algorithms and Data Structures Marcin Sydow Remarks: Comparing Ranks of Functions Sometimes the following technique is useful. Ranks of some 2 functions f(n) and g(n) can be compared by computing the following limit: limn→∞ f(n) g(n) there are 3 possible cases for the limit: 1 ∞ - in that case f(n)=ω(g(n)) (f has higher rank) 2 a positive constant - in that case f(n)=Θ(g(n)) (the same ranks) 3 zero - in that case f(n)=o(g(n)) (lowercase o) (g has higher rank)
  • 33. Algorithms and Data Structures Marcin Sydow The Most Common Ranks of Functions constant (e.g. S(n) = 3 = Θ(1)) logarithmic (e.g. W(n) = 2 + lg2n = Θ(log(n))) linear (e.g. A(n) = 2n + 1 = Θ(n)) linear-logarithmic (e.g. A(n) = 1.44 · nlog(n) = Θ(nlog(n))) square (e.g. W(n) = n2 + 4 = Θ(n2 )) cubic (e.g. A(n) = Θ(n3 )) sub-exponential (e.g. A(n) = Θ(nlog(n))) exponential (e.g. A(n) = Θ(2 n)) factorial (e.g. W(n) = Θ(n!)) In simplication: in practise, an over-polynomial rank of time complexity is considered as unacceptably high In case of space complexity, even linear rank is considered as very high
  • 34. Algorithms and Data Structures Marcin Sydow Questions/Problems: How to measure the speed of algorithm What 2 things should be determined before starting assessing the time complexity of an algorithm What is a dominating operation Denition of Time Complexity of Algorithm Denition of Space Complexity of Algorithm Denition of Pessimistic Time Complexity Denition of Average Time Complexity Be able to determine time complexity for simple algorithms What is the purpose of the asymptotic notation Denition and interpretation of the O() notation Denitions (and interpretations) of the other types of asymptotic notations Ability to express rank of a given function with the asymptotic notation