SlideShare una empresa de Scribd logo
1 de 73
Growth of Functions
Lecture 8, CMSC 56
Allyn Joy D. Calcaben
Big – O Notation
Used to measure how well a computer algorithm scales as the
amount of data involved increases.
Big – O Notation
Used to measure how well a computer algorithm scales as the
amount of data involved increases.
Not a measure of speed but a measure of how well an
algorithm scales.
Big – O Notation
Big – O Notation is also known as Landau Notation
Named after Edmund Landau
He didn’t invent the notation, he popularized it
Ironic that he popularized Big – O as he was known to be an
exact and meticulous mathematician
Landau Notation
If n = 1: 45n3 + 20n2 + 19 =
Example
If n = 1: 45n3 + 20n2 + 19 = 84
Example
If n = 1: 45n3 + 20n2 + 19 = 84
If n = 2: 45n3 + 20n2 + 19 =
Example
If n = 1: 45n3 + 20n2 + 19 = 84
If n = 2: 45n3 + 20n2 + 19 = 459
Example
If n = 1: 45n3 + 20n2 + 19 = 84
If n = 2: 45n3 + 20n2 + 19 = 459
If n = 10: 45n3 + 20n2 + 19 =
Example
If n = 1: 45n3 + 20n2 + 19 = 84
If n = 2: 45n3 + 20n2 + 19 = 459
If n = 10: 45n3 + 20n2 + 19 = 47, 019
45,000 + 2,000 + 19
Example
If n = 100: 45n3 + 20n2 + 19
Removing Unimportant Things
If n = 100: 45n3 + 20n2 + 19
= 45, 000, 000 + 200, 000 + 19
Removing Unimportant Things
If n = 100: 45n3 + 20n2 + 19
= 45, 000, 000 + 200, 000 + 19
= 45, 200, 019
Removing Unimportant Things
If n = 100: 45n3 + 20n2 + 19
= 45, 000, 000 + 200, 000 + 19
= 45, 200, 019
= O(N3)
Removing Unimportant Things
“Leaving away all the unnecessary things that we don’t care
about when comparing algorithms.”
Big – O Notation
2n2 + 23 vs. 2n2 + 27
Example
2n2 + 23 vs. 2n2 + 27
Essentially they have the same running time.
This is another simplification.
Solution
Definition 1
Given A = f(n), B = g(n) grows faster than f(n), then
there exists a number n’ and a constant c so that c•g(n’) ≥ f(n’)
for all n’’ > n, we have g(n’’) ≥ f(n’’).
Big – O Notation
Definition 1
Given A = f(n), B = g(n) grows faster than f(n), then
there exists a number n’ and a constant c so that c•g(n’) ≥ f(n’)
for all n’’ > n, we have g(n’’) ≥ f(n’’).
Since we don’t want to care about constants, we include c so that we can
scale g(n). That is, even if we multiply g(n) with a constant c, and it still
outgrows f(n), we can still say that g(n) runs at least as fast as f(n).
Big – O Notation
If the two conditions hold true, we say that f(n) ϵ O(g(n))
f(n) is contained in Big O of g(n)
Big O means that g(n) is a function that runs at least as fast as f(n).
Big – O Notation
f(n)
g(n)h(n)
n
Comparing the Growth Rates
Get ¼ and answer. Which of the ff. is true? Write True or False
for each number.
1. h(n) ϵ O(f(n))
2. h(n) ϵ O(g(n))
3. g(n) ϵ O(f(n))
4. g(n) ϵ O(h(n))
5. f(n) ϵ O(g(n))
6. f(n) ϵ O(h(n))
Comparing the Growth Rates
f(n)
g(n)h(n)
n
Get ¼ and answer. Which of the ff. is true? Write True or False
for each number.
1. h(n) ϵ O(f(n))
2. h(n) ϵ O(g(n))
3. g(n) ϵ O(f(n))
4. g(n) ϵ O(h(n))
5. f(n) ϵ O(g(n))
6. f(n) ϵ O(h(n))
Comparing the Growth Rates
f(n)
g(n)h(n)
n
Allow us to concentrate on the fastest growing part of the
function and leave out the involved constants
Importance
Simply about looking at which part of the function grows the
fastest.
A convenient way of describing the growth of the function
while ignoring the distracting and unnecessary details
Big – O Notation
f(n) = O(g(n)) is also an accepted notation
f(n) ϵ O(g(n)) is more accurate, since O(g(n)) is a set of functions.
Big – O Notation
Algorithm A RT: 3n2 – n + 10
Algorithm B RT: 2n – 50n + 256
Which algorithm is preferable in general?
Exercise
Algorithm A RT: 3n2 – n + 10
Algorithm B RT: 2n – 50n + 256
Which algorithm is preferable in general?
But, this is for general cases.
For small inputs, algorithm B might be equal to algorithm A or
better.
Solution
Algorithm A RT: 3n2 – n + 10
Algorithm B RT: 2n – 50n + 256
If n = 5: 3n2 – n + 10 = 80
2n – 50n + 256 = 38
If n = 100: 3n2 – n + 10 = 29910
2n – 50n + 256 = 1267650600228229401496703200632
Analysis
1. 3n + 1 ϵ _______
2. 18n2 – 50 ϵ _______
3. 9n4 + 18 ϵ _______
4. 30n6 + 2n + 123 ϵ _______
5. 2nn2 + 30n6 + 123 ϵ _______
More Example
1. 3n + 1 ϵ O(n)
2. 18n2 – 50 ϵ O(n2)
3. 9n4 + 18 ϵ O(n4)
4. 30n6 + 2n + 123 ϵ O(2n)
5. 2nn2 + 30n6 + 123 ϵ O(2n n2)
More Example
O(1)
O(log N)
O(N)
O(N log N)
O(N2)
O(N3)
O(2n)
Big – O Notation
3n + 1 ϵ O(n2)
True / False?
More Examples
3n + 1 ϵ O(n2)
True / False? TRUE, but NOT TIGHT
More Examples
18n2 – 50 ϵ O(n3)
True / False?
If true, tightly bound / not?
If not tightly bound, what is the tighter bound?
More Examples
18n2 – 50 ϵ O(n3)
True / False? TRUE
If true, tightly bound / not? NOT TIGHTLY BOUND
If not tightly bound, what is the tighter bound? O(n2)
More Examples
Write Correct / Incorrect, Tight / Not Tight
1. 4n2 - 300n + 12 ∈ O(n2)
2. 4n2 - 300n + 12 ∈ O(n3)
3. 3n + 5n2 - 3n ∈ O(n2)
4. 3n + 5n2 - 3n ∈ O(4n)
5. 3n + 5n2 - 3n ∈ O(3n)
6. 50•2nn2 + 5n - log(n) ∈ O(2n)
On Your Seats (1/4)
Write Correct / Incorrect, Tight / Not Tight
1. 4n2 - 300n + 12 ∈ O(n2) CORRECT, TIGHT
2. 4n2 - 300n + 12 ∈ O(n3) CORRECT, NOT TIGHT
3. 3n + 5n2 - 3n ∈ O(n2) INCORRECT, NOT TIGHT
4. 3n + 5n2 - 3n ∈ O(4n) CORRECT, NOT TIGHT
5. 3n + 5n2 - 3n ∈ O(3n) CORRECT, TIGHT
6. 50•2nn2 + 5n - log(n) ∈ O(2n) INCORRECT, NOT TIGHT
On Your Seats (1/4)
O(1)
O(log N)
O(N)
O(N log N)
O(N2)
O(N3)
O(2n)
Big – O Notation
O(1)
Constant
Description: Statement
Example: Adding two numbers
c = a + b
O(1)
Algorithm that will execute at the same amount of time
regardless of the amount of data.
Or simply,
Code that will execute at the same amount of time no matter
how big the array is.
O(1)
Example: Adding element to array
list.append(x)
O(1)
O(log N)
Logarithmic
Description: Divide in Half
Data is decreased roughly 50% each time through the algorithm
O(log N)
Example: Binary Search
O(log N)
O(N)
Linear
Description: Loop
Time to complete will grow in direct proportion to the amount of
data.
Example: Factorial of N using Loops
for i in range (1, N+1):
factorial *= i
O(N)
Example: Finding the Maximum
O(N)
Example: Finding the Maximum
Look in exactly each item in the array
Big difference if it was a 10 – item array vs. a 10
thousand – item array
O(N)
Example: Linear Search
O(N)
O(n log N)
Linearithmic / Loglinear
Description: Divide and Conquer
O(n log N)
Example: Merge Sort
O(n log N)
Example: Merge Sort
O(n log N)
O(N2)
Quadratic
Description: Double Loop
Time to complete will grow proportional to the square of amount
of data
O(N2)
Example: Bubble Sort
O(N2)
Example: Insertion Sort
O(N2)
O(N3)
Cubic
Description: Triple Loop
O(N3)
O(2n)
Exponential
Description: Exhaustive Search (Brute Force*)
O(2n)
Implications
Given an algorithm that runs in ___ time, the computer can solve a
problem size of _____ in a matter of minutes.
Practical Implications
Given an algorithm that runs in ___ time, the computer can solve a
problem size of _____ in a matter of minutes.
Constant: any
Logarithmic: any
Linear: billions
Loglinear: hundreds of millions
Quadratic: tens of thousands
Cubic: thousands
Exponential: 30
Practical Implications
Best Case, Worst Case
count = 0
for each character in string:
if character == ‘a’:
count += 1
Best Case, Worst Case
Best case: 2n + 1
Worst case: 3n
Running Time
We observe the ff. from the algorithm:
1. Each character in the string is considered at most once
2. For each character in the input string, a constant no. of steps
is performed (2 or 3)
Running Time
We observe the ff. from the algorithm:
1. Each character in the string is considered at most once
2. For each character in the input string, a constant no. of steps
is performed (2 or 3)
With Big – O, we say c1n + c2 ϵ O(n)
We say that the running time of the algorithm is O(n) or linear
time
Running Time
Any Questions?

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Discrete Math Presentation(Rules of Inference)
Discrete Math Presentation(Rules of Inference)Discrete Math Presentation(Rules of Inference)
Discrete Math Presentation(Rules of Inference)
 
Recurrence relations
Recurrence relationsRecurrence relations
Recurrence relations
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Lec 01 proposition (Discrete Mathematics)
Lec 01   proposition (Discrete Mathematics)Lec 01   proposition (Discrete Mathematics)
Lec 01 proposition (Discrete Mathematics)
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Unit 1 rules of inference
Unit 1  rules of inferenceUnit 1  rules of inference
Unit 1 rules of inference
 
Big o notation
Big o notationBig o notation
Big o notation
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logic
 
Functions in discrete mathematics
Functions in discrete mathematicsFunctions in discrete mathematics
Functions in discrete mathematics
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
5.2 Strong Induction
5.2 Strong Induction5.2 Strong Induction
5.2 Strong Induction
 
Mathematical induction by Animesh Sarkar
Mathematical induction by Animesh SarkarMathematical induction by Animesh Sarkar
Mathematical induction by Animesh Sarkar
 

Similar a CMSC 56 | Lecture 8: Growth of Functions

Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and ComplexityRajandeep Gill
 
Design and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptDesign and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptsrushtiivp
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptxarslanzaheer14
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...DebiPrasadSen
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationzukun
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistGatewayggg Testeru
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations iAli mahmood
 
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
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notationsTarikuDabala1
 

Similar a CMSC 56 | Lecture 8: Growth of Functions (20)

Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
big_oh
big_ohbig_oh
big_oh
 
algorithm_analysis1
algorithm_analysis1algorithm_analysis1
algorithm_analysis1
 
lecture 1
lecture 1lecture 1
lecture 1
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Design and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptDesign and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt ppt
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notation
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Time complexity
Time complexityTime complexity
Time complexity
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabist
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations i
 
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 Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
analysis.ppt
analysis.pptanalysis.ppt
analysis.ppt
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
Lecture3(b).pdf
Lecture3(b).pdfLecture3(b).pdf
Lecture3(b).pdf
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notations
 

Más de allyn joy calcaben

CMSC 56 | Lecture 17: Matrices
CMSC 56 | Lecture 17: MatricesCMSC 56 | Lecture 17: Matrices
CMSC 56 | Lecture 17: Matricesallyn joy calcaben
 
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial OrderingCMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Orderingallyn joy calcaben
 
CMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of RelationsCMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of Relationsallyn joy calcaben
 
CMSC 56 | Lecture 14: Representing Relations
CMSC 56 | Lecture 14: Representing RelationsCMSC 56 | Lecture 14: Representing Relations
CMSC 56 | Lecture 14: Representing Relationsallyn joy calcaben
 
CMSC 56 | Lecture 13: Relations and their Properties
CMSC 56 | Lecture 13: Relations and their PropertiesCMSC 56 | Lecture 13: Relations and their Properties
CMSC 56 | Lecture 13: Relations and their Propertiesallyn joy calcaben
 
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program CorrectnessCMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctnessallyn joy calcaben
 
CMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical InductionCMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical Inductionallyn joy calcaben
 
CMSC 56 | Lecture 10: Integer Representations & Algorithms
CMSC 56 | Lecture 10: Integer Representations & AlgorithmsCMSC 56 | Lecture 10: Integer Representations & Algorithms
CMSC 56 | Lecture 10: Integer Representations & Algorithmsallyn joy calcaben
 
CMSC 56 | Lecture 9: Functions Representations
CMSC 56 | Lecture 9: Functions RepresentationsCMSC 56 | Lecture 9: Functions Representations
CMSC 56 | Lecture 9: Functions Representationsallyn joy calcaben
 
CMSC 56 | Lecture 4: Rules of Inference
CMSC 56 | Lecture 4: Rules of InferenceCMSC 56 | Lecture 4: Rules of Inference
CMSC 56 | Lecture 4: Rules of Inferenceallyn joy calcaben
 
CMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set OperationsCMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set Operationsallyn joy calcaben
 
CMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and StrategyCMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and Strategyallyn joy calcaben
 
CMSC 56 | Lecture 3: Predicates & Quantifiers
CMSC 56 | Lecture 3: Predicates & QuantifiersCMSC 56 | Lecture 3: Predicates & Quantifiers
CMSC 56 | Lecture 3: Predicates & Quantifiersallyn joy calcaben
 
CMSC 56 | Lecture 2: Propositional Equivalences
CMSC 56 | Lecture 2: Propositional EquivalencesCMSC 56 | Lecture 2: Propositional Equivalences
CMSC 56 | Lecture 2: Propositional Equivalencesallyn joy calcaben
 
CMSC 56 | Lecture 1: Propositional Logic
CMSC 56 | Lecture 1: Propositional LogicCMSC 56 | Lecture 1: Propositional Logic
CMSC 56 | Lecture 1: Propositional Logicallyn joy calcaben
 
La Solidaridad and the Propaganda Movement
La Solidaridad and the Propaganda MovementLa Solidaridad and the Propaganda Movement
La Solidaridad and the Propaganda Movementallyn joy calcaben
 
Computer Vision: Feature matching with RANSAC Algorithm
Computer Vision: Feature matching with RANSAC AlgorithmComputer Vision: Feature matching with RANSAC Algorithm
Computer Vision: Feature matching with RANSAC Algorithmallyn joy calcaben
 
Chapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements iiChapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements iiallyn joy calcaben
 

Más de allyn joy calcaben (19)

CMSC 56 | Lecture 17: Matrices
CMSC 56 | Lecture 17: MatricesCMSC 56 | Lecture 17: Matrices
CMSC 56 | Lecture 17: Matrices
 
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial OrderingCMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
 
CMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of RelationsCMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of Relations
 
CMSC 56 | Lecture 14: Representing Relations
CMSC 56 | Lecture 14: Representing RelationsCMSC 56 | Lecture 14: Representing Relations
CMSC 56 | Lecture 14: Representing Relations
 
CMSC 56 | Lecture 13: Relations and their Properties
CMSC 56 | Lecture 13: Relations and their PropertiesCMSC 56 | Lecture 13: Relations and their Properties
CMSC 56 | Lecture 13: Relations and their Properties
 
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program CorrectnessCMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
CMSC 56 | Lecture 12: Recursive Definition & Algorithms, and Program Correctness
 
CMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical InductionCMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical Induction
 
CMSC 56 | Lecture 10: Integer Representations & Algorithms
CMSC 56 | Lecture 10: Integer Representations & AlgorithmsCMSC 56 | Lecture 10: Integer Representations & Algorithms
CMSC 56 | Lecture 10: Integer Representations & Algorithms
 
CMSC 56 | Lecture 9: Functions Representations
CMSC 56 | Lecture 9: Functions RepresentationsCMSC 56 | Lecture 9: Functions Representations
CMSC 56 | Lecture 9: Functions Representations
 
CMSC 56 | Lecture 4: Rules of Inference
CMSC 56 | Lecture 4: Rules of InferenceCMSC 56 | Lecture 4: Rules of Inference
CMSC 56 | Lecture 4: Rules of Inference
 
CMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set OperationsCMSC 56 | Lecture 6: Sets & Set Operations
CMSC 56 | Lecture 6: Sets & Set Operations
 
CMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and StrategyCMSC 56 | Lecture 5: Proofs Methods and Strategy
CMSC 56 | Lecture 5: Proofs Methods and Strategy
 
CMSC 56 | Lecture 3: Predicates & Quantifiers
CMSC 56 | Lecture 3: Predicates & QuantifiersCMSC 56 | Lecture 3: Predicates & Quantifiers
CMSC 56 | Lecture 3: Predicates & Quantifiers
 
CMSC 56 | Lecture 2: Propositional Equivalences
CMSC 56 | Lecture 2: Propositional EquivalencesCMSC 56 | Lecture 2: Propositional Equivalences
CMSC 56 | Lecture 2: Propositional Equivalences
 
CMSC 56 | Lecture 1: Propositional Logic
CMSC 56 | Lecture 1: Propositional LogicCMSC 56 | Lecture 1: Propositional Logic
CMSC 56 | Lecture 1: Propositional Logic
 
La Solidaridad and the Propaganda Movement
La Solidaridad and the Propaganda MovementLa Solidaridad and the Propaganda Movement
La Solidaridad and the Propaganda Movement
 
Computer Vision: Feature matching with RANSAC Algorithm
Computer Vision: Feature matching with RANSAC AlgorithmComputer Vision: Feature matching with RANSAC Algorithm
Computer Vision: Feature matching with RANSAC Algorithm
 
Chapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements iiChapter 7 expressions and assignment statements ii
Chapter 7 expressions and assignment statements ii
 
#11 osteoporosis
#11 osteoporosis#11 osteoporosis
#11 osteoporosis
 

Último

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
 
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
 
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
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
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
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
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
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Último (20)

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...
 
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...
 
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
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
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
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
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
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

CMSC 56 | Lecture 8: Growth of Functions

  • 1. Growth of Functions Lecture 8, CMSC 56 Allyn Joy D. Calcaben
  • 2. Big – O Notation
  • 3. Used to measure how well a computer algorithm scales as the amount of data involved increases. Big – O Notation
  • 4. Used to measure how well a computer algorithm scales as the amount of data involved increases. Not a measure of speed but a measure of how well an algorithm scales. Big – O Notation
  • 5. Big – O Notation is also known as Landau Notation Named after Edmund Landau He didn’t invent the notation, he popularized it Ironic that he popularized Big – O as he was known to be an exact and meticulous mathematician Landau Notation
  • 6. If n = 1: 45n3 + 20n2 + 19 = Example
  • 7. If n = 1: 45n3 + 20n2 + 19 = 84 Example
  • 8. If n = 1: 45n3 + 20n2 + 19 = 84 If n = 2: 45n3 + 20n2 + 19 = Example
  • 9. If n = 1: 45n3 + 20n2 + 19 = 84 If n = 2: 45n3 + 20n2 + 19 = 459 Example
  • 10. If n = 1: 45n3 + 20n2 + 19 = 84 If n = 2: 45n3 + 20n2 + 19 = 459 If n = 10: 45n3 + 20n2 + 19 = Example
  • 11. If n = 1: 45n3 + 20n2 + 19 = 84 If n = 2: 45n3 + 20n2 + 19 = 459 If n = 10: 45n3 + 20n2 + 19 = 47, 019 45,000 + 2,000 + 19 Example
  • 12. If n = 100: 45n3 + 20n2 + 19 Removing Unimportant Things
  • 13. If n = 100: 45n3 + 20n2 + 19 = 45, 000, 000 + 200, 000 + 19 Removing Unimportant Things
  • 14. If n = 100: 45n3 + 20n2 + 19 = 45, 000, 000 + 200, 000 + 19 = 45, 200, 019 Removing Unimportant Things
  • 15. If n = 100: 45n3 + 20n2 + 19 = 45, 000, 000 + 200, 000 + 19 = 45, 200, 019 = O(N3) Removing Unimportant Things
  • 16. “Leaving away all the unnecessary things that we don’t care about when comparing algorithms.” Big – O Notation
  • 17. 2n2 + 23 vs. 2n2 + 27 Example
  • 18. 2n2 + 23 vs. 2n2 + 27 Essentially they have the same running time. This is another simplification. Solution
  • 19. Definition 1 Given A = f(n), B = g(n) grows faster than f(n), then there exists a number n’ and a constant c so that c•g(n’) ≥ f(n’) for all n’’ > n, we have g(n’’) ≥ f(n’’). Big – O Notation
  • 20. Definition 1 Given A = f(n), B = g(n) grows faster than f(n), then there exists a number n’ and a constant c so that c•g(n’) ≥ f(n’) for all n’’ > n, we have g(n’’) ≥ f(n’’). Since we don’t want to care about constants, we include c so that we can scale g(n). That is, even if we multiply g(n) with a constant c, and it still outgrows f(n), we can still say that g(n) runs at least as fast as f(n). Big – O Notation
  • 21. If the two conditions hold true, we say that f(n) ϵ O(g(n)) f(n) is contained in Big O of g(n) Big O means that g(n) is a function that runs at least as fast as f(n). Big – O Notation
  • 23. Get ¼ and answer. Which of the ff. is true? Write True or False for each number. 1. h(n) ϵ O(f(n)) 2. h(n) ϵ O(g(n)) 3. g(n) ϵ O(f(n)) 4. g(n) ϵ O(h(n)) 5. f(n) ϵ O(g(n)) 6. f(n) ϵ O(h(n)) Comparing the Growth Rates f(n) g(n)h(n) n
  • 24. Get ¼ and answer. Which of the ff. is true? Write True or False for each number. 1. h(n) ϵ O(f(n)) 2. h(n) ϵ O(g(n)) 3. g(n) ϵ O(f(n)) 4. g(n) ϵ O(h(n)) 5. f(n) ϵ O(g(n)) 6. f(n) ϵ O(h(n)) Comparing the Growth Rates f(n) g(n)h(n) n
  • 25. Allow us to concentrate on the fastest growing part of the function and leave out the involved constants Importance
  • 26. Simply about looking at which part of the function grows the fastest. A convenient way of describing the growth of the function while ignoring the distracting and unnecessary details Big – O Notation
  • 27. f(n) = O(g(n)) is also an accepted notation f(n) ϵ O(g(n)) is more accurate, since O(g(n)) is a set of functions. Big – O Notation
  • 28. Algorithm A RT: 3n2 – n + 10 Algorithm B RT: 2n – 50n + 256 Which algorithm is preferable in general? Exercise
  • 29. Algorithm A RT: 3n2 – n + 10 Algorithm B RT: 2n – 50n + 256 Which algorithm is preferable in general? But, this is for general cases. For small inputs, algorithm B might be equal to algorithm A or better. Solution
  • 30. Algorithm A RT: 3n2 – n + 10 Algorithm B RT: 2n – 50n + 256 If n = 5: 3n2 – n + 10 = 80 2n – 50n + 256 = 38 If n = 100: 3n2 – n + 10 = 29910 2n – 50n + 256 = 1267650600228229401496703200632 Analysis
  • 31. 1. 3n + 1 ϵ _______ 2. 18n2 – 50 ϵ _______ 3. 9n4 + 18 ϵ _______ 4. 30n6 + 2n + 123 ϵ _______ 5. 2nn2 + 30n6 + 123 ϵ _______ More Example
  • 32. 1. 3n + 1 ϵ O(n) 2. 18n2 – 50 ϵ O(n2) 3. 9n4 + 18 ϵ O(n4) 4. 30n6 + 2n + 123 ϵ O(2n) 5. 2nn2 + 30n6 + 123 ϵ O(2n n2) More Example
  • 33. O(1) O(log N) O(N) O(N log N) O(N2) O(N3) O(2n) Big – O Notation
  • 34. 3n + 1 ϵ O(n2) True / False? More Examples
  • 35. 3n + 1 ϵ O(n2) True / False? TRUE, but NOT TIGHT More Examples
  • 36. 18n2 – 50 ϵ O(n3) True / False? If true, tightly bound / not? If not tightly bound, what is the tighter bound? More Examples
  • 37. 18n2 – 50 ϵ O(n3) True / False? TRUE If true, tightly bound / not? NOT TIGHTLY BOUND If not tightly bound, what is the tighter bound? O(n2) More Examples
  • 38. Write Correct / Incorrect, Tight / Not Tight 1. 4n2 - 300n + 12 ∈ O(n2) 2. 4n2 - 300n + 12 ∈ O(n3) 3. 3n + 5n2 - 3n ∈ O(n2) 4. 3n + 5n2 - 3n ∈ O(4n) 5. 3n + 5n2 - 3n ∈ O(3n) 6. 50•2nn2 + 5n - log(n) ∈ O(2n) On Your Seats (1/4)
  • 39. Write Correct / Incorrect, Tight / Not Tight 1. 4n2 - 300n + 12 ∈ O(n2) CORRECT, TIGHT 2. 4n2 - 300n + 12 ∈ O(n3) CORRECT, NOT TIGHT 3. 3n + 5n2 - 3n ∈ O(n2) INCORRECT, NOT TIGHT 4. 3n + 5n2 - 3n ∈ O(4n) CORRECT, NOT TIGHT 5. 3n + 5n2 - 3n ∈ O(3n) CORRECT, TIGHT 6. 50•2nn2 + 5n - log(n) ∈ O(2n) INCORRECT, NOT TIGHT On Your Seats (1/4)
  • 40. O(1) O(log N) O(N) O(N log N) O(N2) O(N3) O(2n) Big – O Notation
  • 41. O(1)
  • 43. Algorithm that will execute at the same amount of time regardless of the amount of data. Or simply, Code that will execute at the same amount of time no matter how big the array is. O(1)
  • 44. Example: Adding element to array list.append(x) O(1)
  • 46. Logarithmic Description: Divide in Half Data is decreased roughly 50% each time through the algorithm O(log N)
  • 48. O(N)
  • 49. Linear Description: Loop Time to complete will grow in direct proportion to the amount of data. Example: Factorial of N using Loops for i in range (1, N+1): factorial *= i O(N)
  • 50. Example: Finding the Maximum O(N)
  • 51. Example: Finding the Maximum Look in exactly each item in the array Big difference if it was a 10 – item array vs. a 10 thousand – item array O(N)
  • 54. Linearithmic / Loglinear Description: Divide and Conquer O(n log N)
  • 57. O(N2)
  • 58. Quadratic Description: Double Loop Time to complete will grow proportional to the square of amount of data O(N2)
  • 61. O(N3)
  • 63. O(2n)
  • 66. Given an algorithm that runs in ___ time, the computer can solve a problem size of _____ in a matter of minutes. Practical Implications
  • 67. Given an algorithm that runs in ___ time, the computer can solve a problem size of _____ in a matter of minutes. Constant: any Logarithmic: any Linear: billions Loglinear: hundreds of millions Quadratic: tens of thousands Cubic: thousands Exponential: 30 Practical Implications
  • 69. count = 0 for each character in string: if character == ‘a’: count += 1 Best Case, Worst Case
  • 70. Best case: 2n + 1 Worst case: 3n Running Time
  • 71. We observe the ff. from the algorithm: 1. Each character in the string is considered at most once 2. For each character in the input string, a constant no. of steps is performed (2 or 3) Running Time
  • 72. We observe the ff. from the algorithm: 1. Each character in the string is considered at most once 2. For each character in the input string, a constant no. of steps is performed (2 or 3) With Big – O, we say c1n + c2 ϵ O(n) We say that the running time of the algorithm is O(n) or linear time Running Time

Notas del editor

  1. Ex. How well will it work using a 10 – element array vs. a 10 thousand – element array?
  2. Ex. How well will it work using a 10 – element array vs. a 10 thousand – element array?
  3. Ex. How well will it work using a 10 – element array vs. a 10 thousand – element array?
  4. Ex. How well will it work using a 10 – element array vs. a 10 thousand – element array?
  5. Algorithm A
  6. True. n2 grows at least as fast as 3n + 1. But this is unusual because we usually try to make the bound as tight as possible.
  7. Constant: any Logarithmic: any Linear: billions Loglinear: hundreds of millions Quadratic: tens of thousands Cubic: thousands Exponential: 30