SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IMohamed Loey
 
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
 
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
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsMohamed Loey
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsMohamed Loey
 
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
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysisSoujanya V
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsSwapnil Agrawal
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 

Was ist angesagt? (20)

Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
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.
 
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
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
chapter 1
chapter 1chapter 1
chapter 1
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern Algorithms
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
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
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Time complexity
Time complexityTime complexity
Time complexity
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie Algorithms Lecture 2: Analysis of Algorithms I

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
 

Ähnlich wie Algorithms Lecture 2: Analysis of Algorithms I (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...
 

Mehr von 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 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
 
PMP Lecture 2: Project Management Framework
PMP Lecture 2: Project Management FrameworkPMP Lecture 2: Project Management Framework
PMP Lecture 2: Project Management FrameworkMohamed Loey
 

Mehr von Mohamed Loey (19)

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 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
 
PMP Lecture 2: Project Management Framework
PMP Lecture 2: Project Management FrameworkPMP Lecture 2: Project Management Framework
PMP Lecture 2: Project Management Framework
 

Kürzlich hochgeladen

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Kürzlich hochgeladen (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Algorithms Lecture 2: Analysis of Algorithms I

  • 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