SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Analysis and Design of Algorithms
Analysis of Algorithms I
Analysis and Design of Algorithms
Analysis of Algorithms
Time complexity
Asymptotic Notations
Big O Notation
Growth Orders
Problems
Analysis and Design of Algorithms
Analysis of Algorithms is the determination of the
amount of time, storage and/or other resources necessary
to execute them.
Analyzing algorithms is called Asymptotic Analysis
Asymptotic Analysis evaluate the performance of an
algorithm
Analysis and Design of Algorithms
Time complexity
Analysis and Design of Algorithms
 time complexity of an algorithm quantifies the amount of time taken
by an algorithm
 We can have three cases to analyze an algorithm:
1) Worst Case
2) Average Case
3) Best Case
Analysis and Design of Algorithms
 Assume the below algorithm using Python code:
Analysis and Design of Algorithms
 Worst Case Analysis: In the worst case analysis, we calculate upper
bound on running time of an algorithm.
Analysis and Design of Algorithms
 Worst Case Analysis: the case that causes maximum number of
operations to be executed.
 For Linear Search, the worst case happens when the element to be
searched is not present in the array. (example : search for number
8)
2 3 5 4 1 7 6
Analysis and Design of Algorithms
 Worst Case Analysis: When x is not present, the search() functions
compares it with all the elements of arr one by one.
Analysis and Design of Algorithms
 The worst case time complexity of linear search would be O(n).
Analysis and Design of Algorithms
 Average Case Analysis: we take all possible inputs and calculate
computing time for all of the inputs.
Analysis and Design of Algorithms
 Best Case Analysis: calculate lower bound on running time of an
algorithm.
Analysis and Design of Algorithms
 The best case time complexity of linear search would be O(1).
Analysis and Design of Algorithms
 Best Case Analysis: the case that causes minimum number of
operations to be executed.
 For Linear Search, the best case occurs when x is present at the first
location. (example : search for number 2)
 So time complexity in the best case would be Θ(1)
2 3 5 4 1 7 6
Analysis and Design of Algorithms
 Most of the times, we do worst case analysis to analyze algorithms.
 The average case analysis is not easy to do in most of the practical
cases and it is rarely done.
 The Best case analysis is bogus. Guaranteeing a lower bound on an
algorithm doesn’t provide any information.
Analysis and Design of Algorithms
1) Big O Notation: is an Asymptotic Notation for the worst case.
2) Ω Notation (omega notation): is an Asymptotic Notation for the
best case.
3) Θ Notation (theta notation) : is an Asymptotic Notation for the
worst case and the best case.
Analysis and Design of Algorithms
Big O Notation
Analysis and Design of Algorithms
1) O(1)
 Time complexity of a function (or set of statements) is considered as
O(1) if it doesn’t contain loop, recursion and call to any other non-
constant time function. For example swap() function has O(1) time
complexity.
Analysis and Design of Algorithms
 A loop or recursion that runs a constant number of times is also
considered as O(1). For example the following loop is O(1).
Analysis and Design of Algorithms
2) O(n)
 Time Complexity of a loop is considered as O(n) if the loop
variables is incremented / decremented by a constant amount. For
example the following loop statements have O(n) time complexity.
Analysis and Design of Algorithms
2) O(n)
Analysis and Design of Algorithms
2) O(n)
 Another Example:
Analysis and Design of Algorithms
3) O(nc)
 Time complexity of nested loops is equal to the number of times the
innermost statement is executed. For example the following loop
statements have O(n2) time complexity
Analysis and Design of Algorithms
3) O(n2)
Analysis and Design of Algorithms
 Another Example
Analysis and Design of Algorithms
4) O(Logn)
 Time Complexity of a loop is considered as O(Logn) if the loop
variables is divided / multiplied by a constant amount.
Analysis and Design of Algorithms
4) O(Logn)
 Another Example
Analysis and Design of Algorithms
5) O(LogLogn)
 Time Complexity of a loop is considered as O(LogLogn) if the loop
variables is reduced / increased exponentially by a constant.
Analysis and Design of Algorithms
5) O(LogLogn)
 Another Example
Analysis and Design of Algorithms
 How to combine time complexities of consecutive loops?
 Time complexity of above code is O(n) + O(m) which is O(n+m)
Analysis and Design of Algorithms
n O(1) O(log(n)) O(n) O(nlog(n)) O(N2) O(2n) O(n!)
1 1 0 1 1 1 2 1
8 1 3 8 24 64 256 40xx103
30 1 5 30 150 900 10x109 210x1032
500 1 9 500 4500 25x104 3x10150 1x101134
1000 1 10 1000 10x103 1x106 1x10301 4x102567
16x103 1 14 16x103 224x103 256x106 - -
1x105 1 17 1x105 17x105 10x109 - -
Analysis and Design of Algorithms
Analysis and Design of Algorithms
Length of Input (N) Worst Accepted Algorithm
≤10 O(N!),O(N6)
≤15 O(2N∗N2)
≤20 O(2N∗N)
≤100 O(N4)
≤400 O(N3)
≤2K O(N2∗logN)
≤10K O(N2)
≤1M O(N∗logN)
≤100M O(N),O(logN),O(1)
Analysis and Design of Algorithms
 Find the complexity
of the below
program:
Analysis and Design of Algorithms
 Solution: Time
Complexity O(n).
Even though the
inner loop is
bounded by n, but
due to break
statement it is
executing only once.
Analysis and Design of Algorithms
 Find the complexity of the below program:
Analysis and Design of Algorithms
 Solution:
Time
O(n2logn)
Analysis and Design of Algorithms
 Find the complexity of the below program:
Analysis and Design of Algorithms
 Solution:
Time
O(n log2n)
Analysis and Design of Algorithms
 Find the
complexity
of the
below
program:
Analysis and Design of Algorithms
 Solution:
Time O(n5)
Analysis and Design of Algorithms
facebook.com/mloey
mohamedloey@gmail.com
twitter.com/mloey
linkedin.com/in/mloey
mloey@fci.bu.edu.eg
mloey.github.io
Analysis and Design of Algorithms
www.YourCompany.com
© 2020 Companyname PowerPoint Business Theme. All Rights Reserved.
THANKS FOR
YOUR TIME

Contenu connexe

Tendances

Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsSwapnil Agrawal
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithmRezwan Siam
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIMohamed Loey
 
Algorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms IIAlgorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms IIMohamed Loey
 
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
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.Tariq Khan
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting AlgorithmsPranay Neema
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structureMeherul1234
 

Tendances (20)

Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
 
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
 
Algorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms IIAlgorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms II
 
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
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
 

En vedette

Convolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningConvolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningMohamed Loey
 
Deep Learning - Overview of my work II
Deep Learning - Overview of my work IIDeep Learning - Overview of my work II
Deep Learning - Overview of my work IIMohamed Loey
 
Computer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption StandardComputer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption StandardMohamed Loey
 
PMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project ManagementPMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project ManagementMohamed Loey
 
Computer Security Lecture 7: RSA
Computer Security Lecture 7: RSAComputer Security Lecture 7: RSA
Computer Security Lecture 7: RSAMohamed Loey
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 

En vedette (6)

Convolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep LearningConvolutional Neural Network Models - Deep Learning
Convolutional Neural Network Models - Deep Learning
 
Deep Learning - Overview of my work II
Deep Learning - Overview of my work IIDeep Learning - Overview of my work II
Deep Learning - Overview of my work II
 
Computer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption StandardComputer Security Lecture 5: Simplified Advanced Encryption Standard
Computer Security Lecture 5: Simplified Advanced Encryption Standard
 
PMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project ManagementPMP Lecture 1: Introduction to Project Management
PMP Lecture 1: Introduction to Project Management
 
Computer Security Lecture 7: RSA
Computer Security Lecture 7: RSAComputer Security Lecture 7: RSA
Computer Security Lecture 7: RSA
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 

Similaire à Analyzing Algorithms' Time Complexity (O(1) to O(n^5

analysis of algorithms
analysis of algorithmsanalysis of algorithms
analysis of algorithmsMyMovies15
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performanceHabitamuAsimare
 
18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)AdityaKhandelwal58
 
Algorithm in Computer, Sorting and Notations
Algorithm in Computer, Sorting  and NotationsAlgorithm in Computer, Sorting  and Notations
Algorithm in Computer, Sorting and NotationsAbid Kohistani
 
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
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptxNishaS88
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisAnindita Kundu
 
Algorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisAlgorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisDhrumil Patel
 
Time_Complexity.pptx
Time_Complexity.pptxTime_Complexity.pptx
Time_Complexity.pptxvivekcommon
 
Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...bekidea
 

Similaire à Analyzing Algorithms' Time Complexity (O(1) to O(n^5 (20)

Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Lec7
Lec7Lec7
Lec7
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 
analysis of algorithms
analysis of algorithmsanalysis of algorithms
analysis of algorithms
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performance
 
18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)
 
Analysis.ppt
Analysis.pptAnalysis.ppt
Analysis.ppt
 
Analysis of algo
Analysis of algoAnalysis of algo
Analysis of algo
 
Algorithm in Computer, Sorting and Notations
Algorithm in Computer, Sorting  and NotationsAlgorithm in Computer, Sorting  and Notations
Algorithm in Computer, Sorting and Notations
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
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 ...
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
Analysis of Algorithum
Analysis of AlgorithumAnalysis of Algorithum
Analysis of Algorithum
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Algorithms : Introduction and Analysis
Algorithms : Introduction and AnalysisAlgorithms : Introduction and Analysis
Algorithms : Introduction and Analysis
 
Time_Complexity.pptx
Time_Complexity.pptxTime_Complexity.pptx
Time_Complexity.pptx
 
Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...
 

Plus de Mohamed Loey

Lecture 6: Deep Learning Applications
Lecture 6: Deep Learning ApplicationsLecture 6: Deep Learning Applications
Lecture 6: Deep Learning ApplicationsMohamed Loey
 
Lecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network ModelsLecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network ModelsMohamed Loey
 
Lecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning FrameworksLecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning FrameworksMohamed Loey
 
Lecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural NetworksLecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural NetworksMohamed Loey
 
Lecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural NetworksLecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural NetworksMohamed Loey
 
Lecture 2: Artificial Neural Network
Lecture 2: Artificial Neural NetworkLecture 2: Artificial Neural Network
Lecture 2: Artificial Neural NetworkMohamed Loey
 
Lecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer VisionLecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer VisionMohamed Loey
 
Design of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer DiseasesDesign of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer DiseasesMohamed Loey
 
Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2Mohamed Loey
 
Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1Mohamed Loey
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsMohamed Loey
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsMohamed Loey
 
Computer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary MaterialComputer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary MaterialMohamed Loey
 
PMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration ManagementPMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration ManagementMohamed Loey
 
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption StandardComputer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption StandardMohamed Loey
 
Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2Mohamed Loey
 
Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1Mohamed Loey
 
Computer Security Lecture 1: Overview
Computer Security Lecture 1: OverviewComputer Security Lecture 1: Overview
Computer Security Lecture 1: OverviewMohamed Loey
 
PMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management ProcessesPMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management ProcessesMohamed Loey
 

Plus de Mohamed Loey (20)

Lecture 6: Deep Learning Applications
Lecture 6: Deep Learning ApplicationsLecture 6: Deep Learning Applications
Lecture 6: Deep Learning Applications
 
Lecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network ModelsLecture 5: Convolutional Neural Network Models
Lecture 5: Convolutional Neural Network Models
 
Lecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning FrameworksLecture 4: Deep Learning Frameworks
Lecture 4: Deep Learning Frameworks
 
Lecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural NetworksLecture 4: How it Works: Convolutional Neural Networks
Lecture 4: How it Works: Convolutional Neural Networks
 
Lecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural NetworksLecture 3: Convolutional Neural Networks
Lecture 3: Convolutional Neural Networks
 
Lecture 2: Artificial Neural Network
Lecture 2: Artificial Neural NetworkLecture 2: Artificial Neural Network
Lecture 2: Artificial Neural Network
 
Lecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer VisionLecture 1: Deep Learning for Computer Vision
Lecture 1: Deep Learning for Computer Vision
 
Design of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer DiseasesDesign of an Intelligent System for Improving Classification of Cancer Diseases
Design of an Intelligent System for Improving Classification of Cancer Diseases
 
Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2Computer Security - CCNA Security - Lecture 2
Computer Security - CCNA Security - Lecture 2
 
Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1Computer Security - CCNA Security - Lecture 1
Computer Security - CCNA Security - Lecture 1
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern Algorithms
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Computer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary MaterialComputer Security Lecture 4.1: DES Supplementary Material
Computer Security Lecture 4.1: DES Supplementary Material
 
PMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration ManagementPMP Lecture 4: Project Integration Management
PMP Lecture 4: Project Integration Management
 
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption StandardComputer Security Lecture 4: Block Ciphers and the Data Encryption Standard
Computer Security Lecture 4: Block Ciphers and the Data Encryption Standard
 
Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2Computer Security Lecture 3: Classical Encryption Techniques 2
Computer Security Lecture 3: Classical Encryption Techniques 2
 
Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1Computer Security Lecture 2: Classical Encryption Techniques 1
Computer Security Lecture 2: Classical Encryption Techniques 1
 
Computer Security Lecture 1: Overview
Computer Security Lecture 1: OverviewComputer Security Lecture 1: Overview
Computer Security Lecture 1: Overview
 
PMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management ProcessesPMP Lecture 3: Project Management Processes
PMP Lecture 3: Project Management Processes
 

Dernier

ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 

Dernier (20)

ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 

Analyzing Algorithms' Time Complexity (O(1) to O(n^5

  • 1. Analysis and Design of Algorithms Analysis of Algorithms I
  • 2. Analysis and Design of Algorithms Analysis of Algorithms Time complexity Asymptotic Notations Big O Notation Growth Orders Problems
  • 3. Analysis and Design of Algorithms Analysis of Algorithms is the determination of the amount of time, storage and/or other resources necessary to execute them. Analyzing algorithms is called Asymptotic Analysis Asymptotic Analysis evaluate the performance of an algorithm
  • 4. Analysis and Design of Algorithms Time complexity
  • 5. Analysis and Design of Algorithms  time complexity of an algorithm quantifies the amount of time taken by an algorithm  We can have three cases to analyze an algorithm: 1) Worst Case 2) Average Case 3) Best Case
  • 6. Analysis and Design of Algorithms  Assume the below algorithm using Python code:
  • 7. Analysis and Design of Algorithms  Worst Case Analysis: In the worst case analysis, we calculate upper bound on running time of an algorithm.
  • 8. Analysis and Design of Algorithms  Worst Case Analysis: the case that causes maximum number of operations to be executed.  For Linear Search, the worst case happens when the element to be searched is not present in the array. (example : search for number 8) 2 3 5 4 1 7 6
  • 9. Analysis and Design of Algorithms  Worst Case Analysis: When x is not present, the search() functions compares it with all the elements of arr one by one.
  • 10. Analysis and Design of Algorithms  The worst case time complexity of linear search would be O(n).
  • 11. Analysis and Design of Algorithms  Average Case Analysis: we take all possible inputs and calculate computing time for all of the inputs.
  • 12. Analysis and Design of Algorithms  Best Case Analysis: calculate lower bound on running time of an algorithm.
  • 13. Analysis and Design of Algorithms  The best case time complexity of linear search would be O(1).
  • 14. Analysis and Design of Algorithms  Best Case Analysis: the case that causes minimum number of operations to be executed.  For Linear Search, the best case occurs when x is present at the first location. (example : search for number 2)  So time complexity in the best case would be Θ(1) 2 3 5 4 1 7 6
  • 15. Analysis and Design of Algorithms  Most of the times, we do worst case analysis to analyze algorithms.  The average case analysis is not easy to do in most of the practical cases and it is rarely done.  The Best case analysis is bogus. Guaranteeing a lower bound on an algorithm doesn’t provide any information.
  • 16. Analysis and Design of Algorithms 1) Big O Notation: is an Asymptotic Notation for the worst case. 2) Ω Notation (omega notation): is an Asymptotic Notation for the best case. 3) Θ Notation (theta notation) : is an Asymptotic Notation for the worst case and the best case.
  • 17. Analysis and Design of Algorithms Big O Notation
  • 18. Analysis and Design of Algorithms 1) O(1)  Time complexity of a function (or set of statements) is considered as O(1) if it doesn’t contain loop, recursion and call to any other non- constant time function. For example swap() function has O(1) time complexity.
  • 19. Analysis and Design of Algorithms  A loop or recursion that runs a constant number of times is also considered as O(1). For example the following loop is O(1).
  • 20. Analysis and Design of Algorithms 2) O(n)  Time Complexity of a loop is considered as O(n) if the loop variables is incremented / decremented by a constant amount. For example the following loop statements have O(n) time complexity.
  • 21. Analysis and Design of Algorithms 2) O(n)
  • 22. Analysis and Design of Algorithms 2) O(n)  Another Example:
  • 23. Analysis and Design of Algorithms 3) O(nc)  Time complexity of nested loops is equal to the number of times the innermost statement is executed. For example the following loop statements have O(n2) time complexity
  • 24. Analysis and Design of Algorithms 3) O(n2)
  • 25. Analysis and Design of Algorithms  Another Example
  • 26. Analysis and Design of Algorithms 4) O(Logn)  Time Complexity of a loop is considered as O(Logn) if the loop variables is divided / multiplied by a constant amount.
  • 27. Analysis and Design of Algorithms 4) O(Logn)  Another Example
  • 28. Analysis and Design of Algorithms 5) O(LogLogn)  Time Complexity of a loop is considered as O(LogLogn) if the loop variables is reduced / increased exponentially by a constant.
  • 29. Analysis and Design of Algorithms 5) O(LogLogn)  Another Example
  • 30. Analysis and Design of Algorithms  How to combine time complexities of consecutive loops?  Time complexity of above code is O(n) + O(m) which is O(n+m)
  • 31. Analysis and Design of Algorithms n O(1) O(log(n)) O(n) O(nlog(n)) O(N2) O(2n) O(n!) 1 1 0 1 1 1 2 1 8 1 3 8 24 64 256 40xx103 30 1 5 30 150 900 10x109 210x1032 500 1 9 500 4500 25x104 3x10150 1x101134 1000 1 10 1000 10x103 1x106 1x10301 4x102567 16x103 1 14 16x103 224x103 256x106 - - 1x105 1 17 1x105 17x105 10x109 - -
  • 32. Analysis and Design of Algorithms
  • 33. Analysis and Design of Algorithms Length of Input (N) Worst Accepted Algorithm ≤10 O(N!),O(N6) ≤15 O(2N∗N2) ≤20 O(2N∗N) ≤100 O(N4) ≤400 O(N3) ≤2K O(N2∗logN) ≤10K O(N2) ≤1M O(N∗logN) ≤100M O(N),O(logN),O(1)
  • 34. Analysis and Design of Algorithms  Find the complexity of the below program:
  • 35. Analysis and Design of Algorithms  Solution: Time Complexity O(n). Even though the inner loop is bounded by n, but due to break statement it is executing only once.
  • 36. Analysis and Design of Algorithms  Find the complexity of the below program:
  • 37. Analysis and Design of Algorithms  Solution: Time O(n2logn)
  • 38. Analysis and Design of Algorithms  Find the complexity of the below program:
  • 39. Analysis and Design of Algorithms  Solution: Time O(n log2n)
  • 40. Analysis and Design of Algorithms  Find the complexity of the below program:
  • 41. Analysis and Design of Algorithms  Solution: Time O(n5)
  • 42. Analysis and Design of Algorithms facebook.com/mloey mohamedloey@gmail.com twitter.com/mloey linkedin.com/in/mloey mloey@fci.bu.edu.eg mloey.github.io
  • 43. Analysis and Design of Algorithms www.YourCompany.com © 2020 Companyname PowerPoint Business Theme. All Rights Reserved. THANKS FOR YOUR TIME