SlideShare a Scribd company logo
Big O Notation
Hamza Mushtaq
Islamia University Bahwalpur
+Marcello Missiroli
IIS Corni, Modena
A Brief Overview
Time Complexity
In the time complexity analysis we define the time as a
function of the problem size and try to estimate the growth
of the execution time with the growth in problem size.
Memory Space
•The space require by the program to save input data and results in memory
(RAM).
History of Big-O-Notation
•Big O notation (with a capital letter O, not a zero), also called Landau's
symbol, is a symbolism used in complexity theory, computer science, and
mathematics to describe the basic behavior of functions. Basically, it tells
you how fast a function grows or declines.
•Landau's symbol comes from the name of the German mathematician
Edmund Landau who invented the notation.
•The letter O is used because the rate of growth of a function is also called
its order.
What is
Big O notation???
It describes
•Efficiency of an Algorithm
•Time Factor of an Algorithm
•Space Complexity of an Algorithm
It is represented by O(n) where n is the number of operations.
Calculations
•Estimate all base operations (assignments,
operations, I/O, Memory access)
•Sum them all
•Remove constants
•Keep largest term only
Example
•Evaluate:
Assignments: 4*n
Arithmetic operations: 2*n*n
I/O: log(n)
•Sum: 4*n+2*n*n+log(n)
•Remove constants &Keep largest term only 2*n*n
→ O(n
2
)
O(1)
void print(int index,int values[]){
cout<<“the value at index”<<index<< “ is
”<<value[index];
}
You can directly access the index element of the
array, so no matter how big the array gets, the time it
takes to access the element won’t change.
CONSTANT COMPLEXITY (VERY GOOD)
O(n)
void print(int index, int values[]){
for(int x=0;x<index;x++) cout<<index<<“
.”<<value[index]<<endl;
}
As you increase the size of the array, the time for this
algorithm will increase proportionally. An array of 50 will take
twice the time as an array of 25 and half the time of an array
of 100.
LINEAR COMPLEXITY (GOOD)
O(n2)
int CompareToAllNumbers (int array1[ ] ,int
index1,int array2[ ],int index2){
for (int x = 0; x < index1; x++)
{bool isMin; for (int y = 0; y <
index2; y++)
{ if( array[x] > array[y])
isMin = false; }
if(isMin) break; }
return array[x];}
If you add one element to array, you need to go through the entire
rest of the array one additional time. As the input grows, the time
required to run the algorithm will grow quite quickly.
POLYNOMIAL COMPLEXITY (BAD THOUGH TOLERABLE)
O(n!)
•Travelling salesman problem
The number of cities increases the runtime also
increases accordingly by a factor of cities factorial.
•Enumerating all possible chess moves
All legal positions can be stored on 4.45*10^46 bits
More than the number of molecules of earth.
EXPONENTIAL COMPLEXITY
– REALLY BAD “INTRACTABLE” PROBLEMS
Summary of Complexity
Constant complexity O(1)
Logarithmic complexity O(log(n))
Linear Complexity O(n)
Pseudolinear Complexity O(nlog(n))
Polynomial Complexity O(n
k
) k>=2
Exponential Complexity O(k
n
)
int CompareSmallestNumber (int array[ ])
{ int x, curMin;
curMin = array[0];
for (x = 1; x < 10; x++)
{ if( array[x] < curMin)
curMin = array[x];}
return curMin;}
int CompareToAllNumbers (int array[ ])
{bool is Min;
int x, y;
for (int x = 0; x < 10; x++)
{ isMin = true;
for (int y = 0; y < 10; y++)
{ if( array[x] > array[y])
isMin = false;
}if(isMin)
break; }
return array[x];}
We are having two different algorithms
to find the smallest element in the array
•Uses array to store elements
•Compares a temporary variable in the array
•The Big O notation for it is O(n)
This algorithm is efficient and effective as its
O is small as compare to the 2nd algorithm
And hence it gives the best result in less time.
•Uses array to store elements
•Compares the array with array itself
•The big O notation for it is O(n2)
This algorithm is less effective than the other
Beacause this algo has a high Big O and hence
It is more time taking and less effective.
Worst --Best ++
SCENARIOS
BEST
AVERAGE
WORST
Best case:
When the algorithm takes less
run time w.r.t the given inputs/data.
Best case also defines as Big Ω.
Average case:
When the algorithm takes
average run time w.r.t to the input /data.
This is also known as BigΘ.
Worst case:
When the algorithm takes higher runtime
as compared to the given inputs/data.
Worst case is also called as Big O.
Best case:
1
Big Ω =Ω(k)≈1.
Average case:
n/2
BigΘ=Θ(n)≈n.
Worst case:
n
Big O = O(n)≈n .
Linear search (n elem) Binary search (n elem)
Best case:
1
Big Ω =Ω(k)≈1.
Average case:
log2(n)-1.
BigΘ=Θ(n)≈log(n).
Worst case:
log2(n)
Big O = O(n)≈log(n) .
Best case (time):
Ω(n)≈n.
Worst case (time):
O(n
2
)≈n
2
.
Worst case (space):
Big O = O(n)≈
2
.
Insertion sort (n elem) Selection sort (n elem)
Best case (time):
Ω(n)≈n..
Worst case (time):
O(n
2
)≈n
2
.
Worst case (space):
O(n)≈
2
.
Best case (time):
Ω(n)≈n.
Worst case (time):
O(n
2
)≈n
2
.
Worst case (space):
Big O = O(n)≈n
2
.
Bubble sort (n elem) Stupid sort (n elem)
Best case (time):
Ω(n)≈n..
Worst case (time):
O(n!)≈n
!
.
Worst case (space):
O(∞)≈∞ .
Nothing
better?
Looking for nlog(n) in
sorting....
Shellsort
Quicksort
Mergesort

More Related Content

What's hot

Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notation
Muthiah Abbhirami
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
stack & queue
stack & queuestack & queue
stack & queue
manju rani
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Poojith Chowdhary
 
Hash tables
Hash tablesHash tables
Hash tables
Rajendran
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
smruti sarangi
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
Daffodil International University
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Hashing
HashingHashing
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
subhashchandra197
 
Time complexity
Time complexityTime complexity
Time complexity
Katang Isip
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAdelina Ahadova
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
Rahul Jamwal
 
Quick sort
Quick sortQuick sort
Quick sort
Dhruv Sabalpara
 

What's hot (20)

Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notation
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
stack & queue
stack & queuestack & queue
stack & queue
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Hash tables
Hash tablesHash tables
Hash tables
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Hash table
Hash tableHash table
Hash table
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Hashing
HashingHashing
Hashing
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Heaps
HeapsHeaps
Heaps
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Time complexity
Time complexityTime complexity
Time complexity
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Searching & Sorting Algorithms
Searching & Sorting AlgorithmsSearching & Sorting Algorithms
Searching & Sorting Algorithms
 
Quick sort
Quick sortQuick sort
Quick sort
 

Similar to Big O Notation

Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptx
EnosSalar
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
Afaq Mansoor Khan
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
Tribhuvan University
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
Venkatesh Iyer
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
ambikavenkatesh2
 
Module 1 notes of data warehousing and data
Module 1 notes of data warehousing and dataModule 1 notes of data warehousing and data
Module 1 notes of data warehousing and data
vijipersonal2012
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 
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
rajesshs31r
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithmsrajatmay1992
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
babuk110
 
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 using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
Narayan Sau
 
Analysis and Algorithms: basic Introduction
Analysis and Algorithms: basic IntroductionAnalysis and Algorithms: basic Introduction
Analysis and Algorithms: basic Introduction
ssuseraf8b2f
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
Mallikarjun Biradar
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
NishaS88
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
Tanya Makkar
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
jayavignesh86
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
iqbalphy1
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
TechVision8
 

Similar to Big O Notation (20)

Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptx
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
 
Module 1 notes of data warehousing and data
Module 1 notes of data warehousing and dataModule 1 notes of data warehousing and data
Module 1 notes of data warehousing and data
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
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
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
Analysis and Algorithms: basic Introduction
Analysis and Algorithms: basic IntroductionAnalysis and Algorithms: basic Introduction
Analysis and Algorithms: basic Introduction
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
 

More from Marcello Missiroli

Algorithmist guide II
Algorithmist guide IIAlgorithmist guide II
Algorithmist guide II
Marcello Missiroli
 
Guida del perfetto Algoritmista I
Guida del perfetto Algoritmista IGuida del perfetto Algoritmista I
Guida del perfetto Algoritmista I
Marcello Missiroli
 
Workshop: Introduzione ad TDD
Workshop: Introduzione ad TDDWorkshop: Introduzione ad TDD
Workshop: Introduzione ad TDD
Marcello Missiroli
 
Dal c a Java (3/3)
Dal c a Java (3/3)Dal c a Java (3/3)
Dal c a Java (3/3)
Marcello Missiroli
 
Dal C a Java (2/3)
Dal C a Java (2/3)Dal C a Java (2/3)
Dal C a Java (2/3)
Marcello Missiroli
 
Dal C a Java (1/3)
Dal C a Java (1/3)Dal C a Java (1/3)
Dal C a Java (1/3)
Marcello Missiroli
 
Variabili
VariabiliVariabili
Sviluppo degli algoritmi
Sviluppo degli algoritmiSviluppo degli algoritmi
Sviluppo degli algoritmi
Marcello Missiroli
 
5 stadi dello sviluppo di un gruppo
5 stadi dello sviluppo di un gruppo5 stadi dello sviluppo di un gruppo
5 stadi dello sviluppo di un gruppo
Marcello Missiroli
 
Vogliamo programmatori stupidi e pigri!
Vogliamo programmatori stupidi e pigri!Vogliamo programmatori stupidi e pigri!
Vogliamo programmatori stupidi e pigri!
Marcello Missiroli
 
Insegnare Agile
Insegnare AgileInsegnare Agile
Insegnare Agile
Marcello Missiroli
 
The Sequel to sql
The Sequel to sqlThe Sequel to sql
The Sequel to sql
Marcello Missiroli
 
L'avvento del programmatore sociale
L'avvento del programmatore socialeL'avvento del programmatore sociale
L'avvento del programmatore sociale
Marcello Missiroli
 
Il ciclo for
Il ciclo forIl ciclo for
Il ciclo for
Marcello Missiroli
 
Lo stack: tipo di dato astratto e implementazione in Java
Lo stack: tipo di dato astratto e implementazione in JavaLo stack: tipo di dato astratto e implementazione in Java
Lo stack: tipo di dato astratto e implementazione in Java
Marcello Missiroli
 
Programmazione a oggetti tramite la macchina del caffé (pt. 3)
Programmazione a oggetti tramite la macchina del caffé (pt. 3)Programmazione a oggetti tramite la macchina del caffé (pt. 3)
Programmazione a oggetti tramite la macchina del caffé (pt. 3)
Marcello Missiroli
 
Controllo di versione e Git
Controllo di versione e GitControllo di versione e Git
Controllo di versione e Git
Marcello Missiroli
 
Ruby in 25 minuti
Ruby in 25 minutiRuby in 25 minuti
Ruby in 25 minuti
Marcello Missiroli
 
Moodle: i compiti (homework)
Moodle: i compiti (homework)Moodle: i compiti (homework)
Moodle: i compiti (homework)
Marcello Missiroli
 
Uefi: l'eterna lotta tra il bene e il male
Uefi: l'eterna lotta tra il bene e il maleUefi: l'eterna lotta tra il bene e il male
Uefi: l'eterna lotta tra il bene e il male
Marcello Missiroli
 

More from Marcello Missiroli (20)

Algorithmist guide II
Algorithmist guide IIAlgorithmist guide II
Algorithmist guide II
 
Guida del perfetto Algoritmista I
Guida del perfetto Algoritmista IGuida del perfetto Algoritmista I
Guida del perfetto Algoritmista I
 
Workshop: Introduzione ad TDD
Workshop: Introduzione ad TDDWorkshop: Introduzione ad TDD
Workshop: Introduzione ad TDD
 
Dal c a Java (3/3)
Dal c a Java (3/3)Dal c a Java (3/3)
Dal c a Java (3/3)
 
Dal C a Java (2/3)
Dal C a Java (2/3)Dal C a Java (2/3)
Dal C a Java (2/3)
 
Dal C a Java (1/3)
Dal C a Java (1/3)Dal C a Java (1/3)
Dal C a Java (1/3)
 
Variabili
VariabiliVariabili
Variabili
 
Sviluppo degli algoritmi
Sviluppo degli algoritmiSviluppo degli algoritmi
Sviluppo degli algoritmi
 
5 stadi dello sviluppo di un gruppo
5 stadi dello sviluppo di un gruppo5 stadi dello sviluppo di un gruppo
5 stadi dello sviluppo di un gruppo
 
Vogliamo programmatori stupidi e pigri!
Vogliamo programmatori stupidi e pigri!Vogliamo programmatori stupidi e pigri!
Vogliamo programmatori stupidi e pigri!
 
Insegnare Agile
Insegnare AgileInsegnare Agile
Insegnare Agile
 
The Sequel to sql
The Sequel to sqlThe Sequel to sql
The Sequel to sql
 
L'avvento del programmatore sociale
L'avvento del programmatore socialeL'avvento del programmatore sociale
L'avvento del programmatore sociale
 
Il ciclo for
Il ciclo forIl ciclo for
Il ciclo for
 
Lo stack: tipo di dato astratto e implementazione in Java
Lo stack: tipo di dato astratto e implementazione in JavaLo stack: tipo di dato astratto e implementazione in Java
Lo stack: tipo di dato astratto e implementazione in Java
 
Programmazione a oggetti tramite la macchina del caffé (pt. 3)
Programmazione a oggetti tramite la macchina del caffé (pt. 3)Programmazione a oggetti tramite la macchina del caffé (pt. 3)
Programmazione a oggetti tramite la macchina del caffé (pt. 3)
 
Controllo di versione e Git
Controllo di versione e GitControllo di versione e Git
Controllo di versione e Git
 
Ruby in 25 minuti
Ruby in 25 minutiRuby in 25 minuti
Ruby in 25 minuti
 
Moodle: i compiti (homework)
Moodle: i compiti (homework)Moodle: i compiti (homework)
Moodle: i compiti (homework)
 
Uefi: l'eterna lotta tra il bene e il male
Uefi: l'eterna lotta tra il bene e il maleUefi: l'eterna lotta tra il bene e il male
Uefi: l'eterna lotta tra il bene e il male
 

Recently uploaded

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

Big O Notation

  • 1. Big O Notation Hamza Mushtaq Islamia University Bahwalpur +Marcello Missiroli IIS Corni, Modena A Brief Overview
  • 2. Time Complexity In the time complexity analysis we define the time as a function of the problem size and try to estimate the growth of the execution time with the growth in problem size.
  • 3. Memory Space •The space require by the program to save input data and results in memory (RAM).
  • 4. History of Big-O-Notation •Big O notation (with a capital letter O, not a zero), also called Landau's symbol, is a symbolism used in complexity theory, computer science, and mathematics to describe the basic behavior of functions. Basically, it tells you how fast a function grows or declines. •Landau's symbol comes from the name of the German mathematician Edmund Landau who invented the notation. •The letter O is used because the rate of growth of a function is also called its order.
  • 5. What is Big O notation???
  • 6. It describes •Efficiency of an Algorithm •Time Factor of an Algorithm •Space Complexity of an Algorithm It is represented by O(n) where n is the number of operations.
  • 7. Calculations •Estimate all base operations (assignments, operations, I/O, Memory access) •Sum them all •Remove constants •Keep largest term only
  • 8. Example •Evaluate: Assignments: 4*n Arithmetic operations: 2*n*n I/O: log(n) •Sum: 4*n+2*n*n+log(n) •Remove constants &Keep largest term only 2*n*n → O(n 2 )
  • 9. O(1) void print(int index,int values[]){ cout<<“the value at index”<<index<< “ is ”<<value[index]; } You can directly access the index element of the array, so no matter how big the array gets, the time it takes to access the element won’t change. CONSTANT COMPLEXITY (VERY GOOD)
  • 10. O(n) void print(int index, int values[]){ for(int x=0;x<index;x++) cout<<index<<“ .”<<value[index]<<endl; } As you increase the size of the array, the time for this algorithm will increase proportionally. An array of 50 will take twice the time as an array of 25 and half the time of an array of 100. LINEAR COMPLEXITY (GOOD)
  • 11. O(n2) int CompareToAllNumbers (int array1[ ] ,int index1,int array2[ ],int index2){ for (int x = 0; x < index1; x++) {bool isMin; for (int y = 0; y < index2; y++) { if( array[x] > array[y]) isMin = false; } if(isMin) break; } return array[x];} If you add one element to array, you need to go through the entire rest of the array one additional time. As the input grows, the time required to run the algorithm will grow quite quickly. POLYNOMIAL COMPLEXITY (BAD THOUGH TOLERABLE)
  • 12. O(n!) •Travelling salesman problem The number of cities increases the runtime also increases accordingly by a factor of cities factorial. •Enumerating all possible chess moves All legal positions can be stored on 4.45*10^46 bits More than the number of molecules of earth. EXPONENTIAL COMPLEXITY – REALLY BAD “INTRACTABLE” PROBLEMS
  • 13.
  • 14. Summary of Complexity Constant complexity O(1) Logarithmic complexity O(log(n)) Linear Complexity O(n) Pseudolinear Complexity O(nlog(n)) Polynomial Complexity O(n k ) k>=2 Exponential Complexity O(k n )
  • 15. int CompareSmallestNumber (int array[ ]) { int x, curMin; curMin = array[0]; for (x = 1; x < 10; x++) { if( array[x] < curMin) curMin = array[x];} return curMin;} int CompareToAllNumbers (int array[ ]) {bool is Min; int x, y; for (int x = 0; x < 10; x++) { isMin = true; for (int y = 0; y < 10; y++) { if( array[x] > array[y]) isMin = false; }if(isMin) break; } return array[x];} We are having two different algorithms to find the smallest element in the array
  • 16. •Uses array to store elements •Compares a temporary variable in the array •The Big O notation for it is O(n) This algorithm is efficient and effective as its O is small as compare to the 2nd algorithm And hence it gives the best result in less time. •Uses array to store elements •Compares the array with array itself •The big O notation for it is O(n2) This algorithm is less effective than the other Beacause this algo has a high Big O and hence It is more time taking and less effective. Worst --Best ++
  • 18. Best case: When the algorithm takes less run time w.r.t the given inputs/data. Best case also defines as Big Ω. Average case: When the algorithm takes average run time w.r.t to the input /data. This is also known as BigΘ. Worst case: When the algorithm takes higher runtime as compared to the given inputs/data. Worst case is also called as Big O.
  • 19. Best case: 1 Big Ω =Ω(k)≈1. Average case: n/2 BigΘ=Θ(n)≈n. Worst case: n Big O = O(n)≈n . Linear search (n elem) Binary search (n elem) Best case: 1 Big Ω =Ω(k)≈1. Average case: log2(n)-1. BigΘ=Θ(n)≈log(n). Worst case: log2(n) Big O = O(n)≈log(n) .
  • 20. Best case (time): Ω(n)≈n. Worst case (time): O(n 2 )≈n 2 . Worst case (space): Big O = O(n)≈ 2 . Insertion sort (n elem) Selection sort (n elem) Best case (time): Ω(n)≈n.. Worst case (time): O(n 2 )≈n 2 . Worst case (space): O(n)≈ 2 .
  • 21. Best case (time): Ω(n)≈n. Worst case (time): O(n 2 )≈n 2 . Worst case (space): Big O = O(n)≈n 2 . Bubble sort (n elem) Stupid sort (n elem) Best case (time): Ω(n)≈n.. Worst case (time): O(n!)≈n ! . Worst case (space): O(∞)≈∞ .
  • 23. Looking for nlog(n) in sorting.... Shellsort Quicksort Mergesort