SlideShare a Scribd company logo
1 of 12
Unit 2.1
Big O Notation
Intro
• When solving a computer science problem there will usually be more than just
one solution.
• These solutions will often be in the form of different algorithms, and you will
generally want to compare the algorithms to see which one is more efficient.
• This is where Big O analysis helps – it gives us some basis for measuring the
efficiency of an algorithm.
• Big O measures the efficiency of an algorithm based on the time it takes for
the algorithm to run as a function of the input size.
Ashim Lamichhane 2
Asymptotic notation
• For example, suppose that an algorithm, running on an input of size n,
takes 6n2 + 100n + 300 machine instructions.
• The 6n2 term becomes larger than the remaining terms, 100 n + 300,
once n becomes large enough, 20 in this case.
• Here's a chart showing values of
6n2 and 100n + 300 for values of
n from 0 to 100:
• We could say “f(n) grows at the order
Of n2”. And write f(n)=O(n2)
Ashim Lamichhane 3
Asymptotic notation
• By dropping the less significant terms and the constant coefficients, we can focus
on the important part of an algorithm's running time.
• When we drop the constant coefficients and the less significant terms, we use
asymptotic notation.
• We'll see three forms of it: big-Θ notation, big-O notation, and big-Ω notation.
Ashim Lamichhane 4
Big-O Notation
Ashim Lamichhane 5
• A function f(x)=O(g(x)) (read as f(x) is big oh of g(x) ) iff there exists two positive
constants c and x0 such that
for all x >= x0, f(x) <= c*g(x)
• Consider an example:
f(x)=5x3+3x2+4 find big O of f(x)
solution:
f(x)= 5x3+3x2+4
we can exclude the lower order polynomial so, f(x)=5x3
since, f(x)<c*g(x), where c=5 and x=3
Thus by definition of big oh O(f(x))=O(x3)
• We use "big-O" notation for occasions such as "the running time
grows at most this much, but it could grow more slowly.”
Ashim Lamichhane 6
• We have a Fibonacci algorithm.
• We're just going to run through it operation by operation and ask how long it
takes.
Ashim Lamichhane 7
Ashim Lamichhane 8
Big Omega (Ω) notation
• Sometimes, we want to say that an algorithm takes at least a certain amount of
time, without providing an upper bound.
• We use big-Ω notation; that's the Greek letter "omega.”
• A function f(x) =Ω (g(x)) (read as f(x) is big omega of g(x) ) iff there exists two
positive constants c and x0 such that for all x >= x0, 0 <= c*g(x) <= f(x).
• Therefore,
f(x)>=c*g(x)
• The above relation says that g(x) is a lower bound of f(x).
Ashim Lamichhane 9
Big Omega (Ω) notation
Ashim Lamichhane 10
Big Theta (Θ) notation
• When we need asymptotically tight bound then we use notation.
• A function f(x) = (g(x)) (read as f(x) is big theta of g(x) ) iff there exists three
positive constants c1, c2 and x0 such that
for all x >= x0, c1*g(x) <= f(x) <= c2*g(x)
Ashim Lamichhane 11
Assignment
• https://github.com/ashim888/dataStructureAndAlgorithm/tree/master/Assignme
nts/assignment_4
NOTE: before submitting please do check
• https://github.com/ashim888/dataStructureAndAlgorithm/tree/master/Assignme
nts
Ashim Lamichhane 12

More Related Content

What's hot

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
02 order of growth
02 order of growth02 order of growth
02 order of growthHira Gul
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAdelina Ahadova
 
Bubble sort
Bubble sortBubble sort
Bubble sortManek Ar
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting AlgorithmsPranay Neema
 
Analysis of algorithn class 2
Analysis of algorithn class 2Analysis of algorithn class 2
Analysis of algorithn class 2Kumar
 
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
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithmsDr Geetha Mohan
 
ANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.pptANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.pptDaveCalapis3
 

What's hot (20)

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Quick sort
Quick sortQuick sort
Quick sort
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Analysis of algorithn class 2
Analysis of algorithn class 2Analysis of algorithn class 2
Analysis of algorithn class 2
 
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
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
ANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.pptANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
ANALYSIS-AND-DESIGN-OF-ALGORITHM.ppt
 

Viewers also liked (20)

9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Queues
QueuesQueues
Queues
 
Linked List
Linked ListLinked List
Linked List
 
Sorting
SortingSorting
Sorting
 
Searching
SearchingSearching
Searching
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notation
 
Big o notation
Big o notationBig o notation
Big o notation
 
Friedman two way analysis of variance by
Friedman two way analysis of  variance byFriedman two way analysis of  variance by
Friedman two way analysis of variance by
 
Complexity
ComplexityComplexity
Complexity
 
Analysis of algo
Analysis of algoAnalysis of algo
Analysis of algo
 
Big o
Big oBig o
Big o
 
Algorithum Analysis
Algorithum AnalysisAlgorithum Analysis
Algorithum Analysis
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
03 Analysis of Algorithms: Probabilistic Analysis
03 Analysis of Algorithms: Probabilistic Analysis03 Analysis of Algorithms: Probabilistic Analysis
03 Analysis of Algorithms: Probabilistic Analysis
 

Similar to Algorithm big o

Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptxTekle12
 
week1 cs72 module 01 temp check 190.pptx
week1 cs72 module 01 temp check 190.pptxweek1 cs72 module 01 temp check 190.pptx
week1 cs72 module 01 temp check 190.pptxhardmarcelia
 
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 unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmssnehajiyani
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..KarthikeyaLanka1
 
Module III - 1 - Orders of Growth.p df
Module III - 1 - Orders of Growth.p   dfModule III - 1 - Orders of Growth.p   df
Module III - 1 - Orders of Growth.p dfKAnurag2
 
Analysis of algorithn class 3
Analysis of algorithn class 3Analysis of algorithn class 3
Analysis of algorithn class 3Kumar
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performanceHabitamuAsimare
 

Similar to Algorithm big o (20)

Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Big o notation
Big o notationBig o notation
Big o notation
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
week1 cs72 module 01 temp check 190.pptx
week1 cs72 module 01 temp check 190.pptxweek1 cs72 module 01 temp check 190.pptx
week1 cs72 module 01 temp check 190.pptx
 
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 ...
 
Algorithms DM
Algorithms DMAlgorithms DM
Algorithms DM
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithms
 
Analysis.ppt
Analysis.pptAnalysis.ppt
Analysis.ppt
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
Analysis of Algorithum
Analysis of AlgorithumAnalysis of Algorithum
Analysis of Algorithum
 
36 greedy
36 greedy36 greedy
36 greedy
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Module III - 1 - Orders of Growth.p df
Module III - 1 - Orders of Growth.p   dfModule III - 1 - Orders of Growth.p   df
Module III - 1 - Orders of Growth.p df
 
Analysis of algorithn class 3
Analysis of algorithn class 3Analysis of algorithn class 3
Analysis of algorithn class 3
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performance
 
Lec7
Lec7Lec7
Lec7
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 

More from Ashim Lamichhane

More from Ashim Lamichhane (9)

UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 

Recently uploaded

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 

Recently uploaded (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 

Algorithm big o

  • 1. Unit 2.1 Big O Notation
  • 2. Intro • When solving a computer science problem there will usually be more than just one solution. • These solutions will often be in the form of different algorithms, and you will generally want to compare the algorithms to see which one is more efficient. • This is where Big O analysis helps – it gives us some basis for measuring the efficiency of an algorithm. • Big O measures the efficiency of an algorithm based on the time it takes for the algorithm to run as a function of the input size. Ashim Lamichhane 2
  • 3. Asymptotic notation • For example, suppose that an algorithm, running on an input of size n, takes 6n2 + 100n + 300 machine instructions. • The 6n2 term becomes larger than the remaining terms, 100 n + 300, once n becomes large enough, 20 in this case. • Here's a chart showing values of 6n2 and 100n + 300 for values of n from 0 to 100: • We could say “f(n) grows at the order Of n2”. And write f(n)=O(n2) Ashim Lamichhane 3
  • 4. Asymptotic notation • By dropping the less significant terms and the constant coefficients, we can focus on the important part of an algorithm's running time. • When we drop the constant coefficients and the less significant terms, we use asymptotic notation. • We'll see three forms of it: big-Θ notation, big-O notation, and big-Ω notation. Ashim Lamichhane 4
  • 5. Big-O Notation Ashim Lamichhane 5 • A function f(x)=O(g(x)) (read as f(x) is big oh of g(x) ) iff there exists two positive constants c and x0 such that for all x >= x0, f(x) <= c*g(x) • Consider an example: f(x)=5x3+3x2+4 find big O of f(x) solution: f(x)= 5x3+3x2+4 we can exclude the lower order polynomial so, f(x)=5x3 since, f(x)<c*g(x), where c=5 and x=3 Thus by definition of big oh O(f(x))=O(x3)
  • 6. • We use "big-O" notation for occasions such as "the running time grows at most this much, but it could grow more slowly.” Ashim Lamichhane 6
  • 7. • We have a Fibonacci algorithm. • We're just going to run through it operation by operation and ask how long it takes. Ashim Lamichhane 7
  • 9. Big Omega (Ω) notation • Sometimes, we want to say that an algorithm takes at least a certain amount of time, without providing an upper bound. • We use big-Ω notation; that's the Greek letter "omega.” • A function f(x) =Ω (g(x)) (read as f(x) is big omega of g(x) ) iff there exists two positive constants c and x0 such that for all x >= x0, 0 <= c*g(x) <= f(x). • Therefore, f(x)>=c*g(x) • The above relation says that g(x) is a lower bound of f(x). Ashim Lamichhane 9
  • 10. Big Omega (Ω) notation Ashim Lamichhane 10
  • 11. Big Theta (Θ) notation • When we need asymptotically tight bound then we use notation. • A function f(x) = (g(x)) (read as f(x) is big theta of g(x) ) iff there exists three positive constants c1, c2 and x0 such that for all x >= x0, c1*g(x) <= f(x) <= c2*g(x) Ashim Lamichhane 11
  • 12. Assignment • https://github.com/ashim888/dataStructureAndAlgorithm/tree/master/Assignme nts/assignment_4 NOTE: before submitting please do check • https://github.com/ashim888/dataStructureAndAlgorithm/tree/master/Assignme nts Ashim Lamichhane 12