SlideShare a Scribd company logo
Today’s Outline
• Admin: Assignment #1 due next thurs. at
11:59pm
• Asymptotic analysis

Asymptotic Analysis
CSE 373
Data Structures & Algorithms
Ruth Anderson
Spring 2007

04/04/08

2

Linear Search vs Binary Search
Linear Search

Binary Search

Best Case

Asymptotic Analysis

Worst Case

So … which algorithm is better?
What tradeoffs can you make?
04/04/08

Fast Computer vs. Slow Computer

04/04/08

5

4

Fast Computer vs. Smart Programmer
(round 1)

04/04/08

6

1
Fast Computer vs. Smart Programmer
(round 2)

Asymptotic Analysis
• Asymptotic analysis looks at the order of the
running time of the algorithm
– A valuable tool when the input gets “large”
– Ignores the effects of different machines or different
implementations of the same algorithm

• Intuitively, to find the asymptotic runtime, throw
away the constants and low-order terms
– Linear search is T(n) = 3n + 2 ∈ O(n)
– Binary search is T(n) = 4 log2n + 4 ∈ O(log n)

04/04/08

7

Remember: the fastest algorithm has the
slowest growing function for its runtime
8

04/04/08

Order Notation: Intuition

Asymptotic Analysis
• Eliminate low order terms
– 4n + 5 ⇒
– 0.5 n log n + 2n + 7 ⇒
– n3 + 2n + 3n ⇒

f(n) = n3 + 2n2
g(n) = 100n2 + 1000

• Eliminate coefficients
– 4n ⇒
– 0.5 n log n ⇒
– n log n2 =>

04/04/08

9

Although not yet apparent, as n gets “sufficiently
large”, f(n) will be “greater than or equal to” g(n)10
04/04/08

Order Notation: Definition

Definition of Order Notation
•

Upper bound: T(n) = O(f(n))

O( f(n) ) : a set or class of functions

Big-O

Exist constants c and n’ such that
T(n) ≤ c f(n) for all n ≥ n’

•

Lower bound: T(n) = Ω(g(n))

g(n) ∈ O( f(n) ) iff there exist consts c and n0 such that:
g(n) ≤ c f(n) for all n ≥ n0

Omega

Exist constants c and n’ such that
T(n) ≥ c g(n) for all n ≥ n’

•

Tight bound: T(n) = θ(f(n))

Example: g(n) =1000n vs. f(n) = n2
Is g(n) ∈ O( f(n) ) ?
Pick: n0 = 1000, c = 1

Theta

When both hold:
T(n) = O(f(n))
T(n) = Ω(f(n))
04/04/08

11

04/04/08

12

2
Order Notation: Example

Notation Notes
Note: Sometimes, you’ll see the notation:
g(n) = O(f(n)).
This is equivalent to:
g(n) ∈ O(f(n)).
However: The notation
O(f(n)) = g(n)

is meaningless!

(in other words big-O is not symmetric)
04/04/08

13

04/04/08

100n2 + 1000 ≤ 5 (n3 + 2n2) for all n ≥ 19
So f(n) ∈ O( g(n) )

Big-O: Common Names
–
–
–
–
–
–
–
–

constant:
logarithmic:
linear:
log-linear:
quadratic:
cubic:
polynomial:
exponential:

O(1)
O(log n)
O(n)
O(n log n)
O(n2)
O(n3)
O(nk)
O(cn)

14

Meet the Family

(logkn, log n2 ∈ O(log n))

• O( f(n) ) is the set of all functions asymptotically
less than or equal to f(n)
– o( f(n) ) is the set of all functions asymptotically
strictly less than f(n)

• Ω( f(n) ) is the set of all functions asymptotically
greater than or equal to f(n)
– ω( f(n) ) is the set of all functions asymptotically
strictly greater than f(n)

(k is a constant)
(c is a constant > 1)

04/04/08

• θ( f(n) ) is the set of all functions asymptotically
equal to f(n)
15

04/04/08

16

Big-Omega et al. Intuitively

Meet the Family, Formally
• g(n) ∈ O( f(n) ) iff
There exist c and n0 such that g(n) ≤ c f(n) for all n ≥ n0

– g(n) ∈ o( f(n) ) iff
There exists a n0 such that g(n) < c f(n) for all c and n ≥ n0
Equivalent to: limn→∞ g(n)/f(n) = 0

Asymptotic Notation
O
Ω

• g(n) ∈ Ω( f(n) ) iff
There exist c and n0 such that g(n) ≥ c f(n) for all n ≥ n0

θ
o

– g(n) ∈ ω( f(n) ) iff
There exists a n0 such that g(n) > c f(n) for all c and n ≥ n0
Equivalent to: limn→∞ g(n)/f(n) = ∞

ω

Mathematics Relation
≤
≥
=
<
>

• g(n) ∈ θ( f(n) ) iff
g(n) ∈ O( f(n) ) and g(n) ∈ Ω( f(n) )
04/04/08

17

04/04/08

18

3
Pros and Cons of Asymptotic
Analysis

Types of Analysis
Two orthogonal axes:
– bound flavor
• upper bound (O, o)
• lower bound (Ω, ω)
• asymptotically tight (θ)

– analysis case
•
•
•
•
04/04/08

19

worst case (adversary)
average case
best case
“amortized”

04/04/08

Algorithm Analysis Examples

20

Analyzing the Loop

• Consider the following
program segment:

• Total number of times x is incremented is
executed =

x:= 0;
for i = 1 to N do
for j = 1 to i do
x := x + 1;

N

1+ 2 + 3 + ... = ∑ i =

• What is the value of x at
the end?

i =1

N(N + 1)
2

• Congratulations - You’ve just analyzed your first
program!
– Running time of the program is proportional to
N(N+1)/2 for all N
– Big-O ??
04/04/08

21

04/04/08

22

Which Function Grows Faster?

Which Function Grows Faster?

n3 + 2n2 vs.

n3 + 2n2

04/04/08

100n2 + 1000

23

04/04/08

vs. 100n2 + 1000

24

4

More Related Content

What's hot

Recursive algorithms
Recursive algorithmsRecursive algorithms
Recursive algorithms
subhashchandra197
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
junnubabu
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
Rezwan Siam
 
Binary search
Binary searchBinary search
Binary search
AparnaKumari31
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
Ganesh Solanke
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
Rajendran
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
i i
 
Recurrence relation
Recurrence relationRecurrence relation
Recurrence relation
Ajay Chimmani
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
YekoyeTigabuYeko
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary search
nikunjandy
 

What's hot (20)

Recursive algorithms
Recursive algorithmsRecursive algorithms
Recursive algorithms
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
 
Binary search
Binary searchBinary search
Binary search
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
 
Recurrence relation
Recurrence relationRecurrence relation
Recurrence relation
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary search
 

Viewers also liked

Made easy notes of Digital electronics Part-1
Made easy notes of Digital electronics Part-1Made easy notes of Digital electronics Part-1
Made easy notes of Digital electronics Part-1
ranjeet kumar singh
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 
Made easy notes of Digital electronics Part-2
Made easy notes of Digital electronics Part-2Made easy notes of Digital electronics Part-2
Made easy notes of Digital electronics Part-2ranjeet kumar singh
 
Digital Electronics Notes
Digital Electronics Notes Digital Electronics Notes
Digital Electronics Notes
Srikrishna Thota
 
Computer Networks Foundation - Study Notes
Computer Networks Foundation - Study NotesComputer Networks Foundation - Study Notes
Computer Networks Foundation - Study Notes
Marius FAILLOT DEVARRE
 
Gate mathematics
Gate mathematicsGate mathematics
Gate mathematics
Vivek Thakur
 
Digital notes
Digital notesDigital notes
Digital notesstivengo2
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
K Hari Shankar
 
Made easy notes of Digital electronics Part-3
Made easy notes of Digital electronics Part-3Made easy notes of Digital electronics Part-3
Made easy notes of Digital electronics Part-3
ranjeet kumar singh
 
Gate mathematics questions all branch by s k mondal
Gate mathematics questions all branch by s k mondalGate mathematics questions all branch by s k mondal
Gate mathematics questions all branch by s k mondal
Aashishv
 
Advanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems SolutionAdvanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems Solution
Joe Christensen
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
 
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
 
Lecture 3
Lecture 3Lecture 3
Lecture 3Mr SMAK
 
Computer architecture kai hwang
Computer architecture   kai hwangComputer architecture   kai hwang
Computer architecture kai hwangSumedha
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
Kumar Avinash
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 

Viewers also liked (18)

Made easy notes of Digital electronics Part-1
Made easy notes of Digital electronics Part-1Made easy notes of Digital electronics Part-1
Made easy notes of Digital electronics Part-1
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Made easy notes of Digital electronics Part-2
Made easy notes of Digital electronics Part-2Made easy notes of Digital electronics Part-2
Made easy notes of Digital electronics Part-2
 
Digital Electronics Notes
Digital Electronics Notes Digital Electronics Notes
Digital Electronics Notes
 
Computer Networks Foundation - Study Notes
Computer Networks Foundation - Study NotesComputer Networks Foundation - Study Notes
Computer Networks Foundation - Study Notes
 
Gate mathematics
Gate mathematicsGate mathematics
Gate mathematics
 
Digital notes
Digital notesDigital notes
Digital notes
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
Made easy notes of Digital electronics Part-3
Made easy notes of Digital electronics Part-3Made easy notes of Digital electronics Part-3
Made easy notes of Digital electronics Part-3
 
Kai hwang solution
Kai hwang solutionKai hwang solution
Kai hwang solution
 
Gate mathematics questions all branch by s k mondal
Gate mathematics questions all branch by s k mondalGate mathematics questions all branch by s k mondal
Gate mathematics questions all branch by s k mondal
 
Advanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems SolutionAdvanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems Solution
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
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
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Computer architecture kai hwang
Computer architecture   kai hwangComputer architecture   kai hwang
Computer architecture kai hwang
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 

Similar to Time complexity (linear search vs binary search)

Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
mustafa sarac
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
pallavidhade2
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
dattakumar4
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
Soujanya V
 
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
srushtiivp
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
Data Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdfData Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdf
RameshaFernando2
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functions
allyn joy calcaben
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
ShaistaRiaz4
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
sohelranasweet
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
Deepak John
 
Lecture3(b).pdf
Lecture3(b).pdfLecture3(b).pdf
Lecture3(b).pdf
ShaistaRiaz4
 
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
arslanzaheer14
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
SiddheshUpadhyay3
 
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Sean Meyn
 
analysis.ppt
analysis.pptanalysis.ppt
analysis.ppt
AarushSharma69
 

Similar to Time complexity (linear search vs binary search) (20)

Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
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
 
lecture 1
lecture 1lecture 1
lecture 1
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Data Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdfData Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdf
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functions
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Lecture3(b).pdf
Lecture3(b).pdfLecture3(b).pdf
Lecture3(b).pdf
 
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
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
 
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
Quasi-Stochastic Approximation: Algorithm Design Principles with Applications...
 
analysis.ppt
analysis.pptanalysis.ppt
analysis.ppt
 

More from Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devices
Kumar
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
Kumar
 
region-filling
region-fillingregion-filling
region-filling
Kumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
Kumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
Kumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
Kumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
Kumar
 
Xml basics
Xml basicsXml basics
Xml basics
Kumar
 
XML Schema
XML SchemaXML Schema
XML Schema
Kumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
Kumar
 
DTD
DTDDTD
DTD
Kumar
 
Applying xml
Applying xmlApplying xml
Applying xml
Kumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Kumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
Kumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
Kumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
Kumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
Kumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
Kumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
Kumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
Kumar
 

More from Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
region-filling
region-fillingregion-filling
region-filling
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 

Recently uploaded

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

Time complexity (linear search vs binary search)

  • 1. Today’s Outline • Admin: Assignment #1 due next thurs. at 11:59pm • Asymptotic analysis Asymptotic Analysis CSE 373 Data Structures & Algorithms Ruth Anderson Spring 2007 04/04/08 2 Linear Search vs Binary Search Linear Search Binary Search Best Case Asymptotic Analysis Worst Case So … which algorithm is better? What tradeoffs can you make? 04/04/08 Fast Computer vs. Slow Computer 04/04/08 5 4 Fast Computer vs. Smart Programmer (round 1) 04/04/08 6 1
  • 2. Fast Computer vs. Smart Programmer (round 2) Asymptotic Analysis • Asymptotic analysis looks at the order of the running time of the algorithm – A valuable tool when the input gets “large” – Ignores the effects of different machines or different implementations of the same algorithm • Intuitively, to find the asymptotic runtime, throw away the constants and low-order terms – Linear search is T(n) = 3n + 2 ∈ O(n) – Binary search is T(n) = 4 log2n + 4 ∈ O(log n) 04/04/08 7 Remember: the fastest algorithm has the slowest growing function for its runtime 8 04/04/08 Order Notation: Intuition Asymptotic Analysis • Eliminate low order terms – 4n + 5 ⇒ – 0.5 n log n + 2n + 7 ⇒ – n3 + 2n + 3n ⇒ f(n) = n3 + 2n2 g(n) = 100n2 + 1000 • Eliminate coefficients – 4n ⇒ – 0.5 n log n ⇒ – n log n2 => 04/04/08 9 Although not yet apparent, as n gets “sufficiently large”, f(n) will be “greater than or equal to” g(n)10 04/04/08 Order Notation: Definition Definition of Order Notation • Upper bound: T(n) = O(f(n)) O( f(n) ) : a set or class of functions Big-O Exist constants c and n’ such that T(n) ≤ c f(n) for all n ≥ n’ • Lower bound: T(n) = Ω(g(n)) g(n) ∈ O( f(n) ) iff there exist consts c and n0 such that: g(n) ≤ c f(n) for all n ≥ n0 Omega Exist constants c and n’ such that T(n) ≥ c g(n) for all n ≥ n’ • Tight bound: T(n) = θ(f(n)) Example: g(n) =1000n vs. f(n) = n2 Is g(n) ∈ O( f(n) ) ? Pick: n0 = 1000, c = 1 Theta When both hold: T(n) = O(f(n)) T(n) = Ω(f(n)) 04/04/08 11 04/04/08 12 2
  • 3. Order Notation: Example Notation Notes Note: Sometimes, you’ll see the notation: g(n) = O(f(n)). This is equivalent to: g(n) ∈ O(f(n)). However: The notation O(f(n)) = g(n) is meaningless! (in other words big-O is not symmetric) 04/04/08 13 04/04/08 100n2 + 1000 ≤ 5 (n3 + 2n2) for all n ≥ 19 So f(n) ∈ O( g(n) ) Big-O: Common Names – – – – – – – – constant: logarithmic: linear: log-linear: quadratic: cubic: polynomial: exponential: O(1) O(log n) O(n) O(n log n) O(n2) O(n3) O(nk) O(cn) 14 Meet the Family (logkn, log n2 ∈ O(log n)) • O( f(n) ) is the set of all functions asymptotically less than or equal to f(n) – o( f(n) ) is the set of all functions asymptotically strictly less than f(n) • Ω( f(n) ) is the set of all functions asymptotically greater than or equal to f(n) – ω( f(n) ) is the set of all functions asymptotically strictly greater than f(n) (k is a constant) (c is a constant > 1) 04/04/08 • θ( f(n) ) is the set of all functions asymptotically equal to f(n) 15 04/04/08 16 Big-Omega et al. Intuitively Meet the Family, Formally • g(n) ∈ O( f(n) ) iff There exist c and n0 such that g(n) ≤ c f(n) for all n ≥ n0 – g(n) ∈ o( f(n) ) iff There exists a n0 such that g(n) < c f(n) for all c and n ≥ n0 Equivalent to: limn→∞ g(n)/f(n) = 0 Asymptotic Notation O Ω • g(n) ∈ Ω( f(n) ) iff There exist c and n0 such that g(n) ≥ c f(n) for all n ≥ n0 θ o – g(n) ∈ ω( f(n) ) iff There exists a n0 such that g(n) > c f(n) for all c and n ≥ n0 Equivalent to: limn→∞ g(n)/f(n) = ∞ ω Mathematics Relation ≤ ≥ = < > • g(n) ∈ θ( f(n) ) iff g(n) ∈ O( f(n) ) and g(n) ∈ Ω( f(n) ) 04/04/08 17 04/04/08 18 3
  • 4. Pros and Cons of Asymptotic Analysis Types of Analysis Two orthogonal axes: – bound flavor • upper bound (O, o) • lower bound (Ω, ω) • asymptotically tight (θ) – analysis case • • • • 04/04/08 19 worst case (adversary) average case best case “amortized” 04/04/08 Algorithm Analysis Examples 20 Analyzing the Loop • Consider the following program segment: • Total number of times x is incremented is executed = x:= 0; for i = 1 to N do for j = 1 to i do x := x + 1; N 1+ 2 + 3 + ... = ∑ i = • What is the value of x at the end? i =1 N(N + 1) 2 • Congratulations - You’ve just analyzed your first program! – Running time of the program is proportional to N(N+1)/2 for all N – Big-O ?? 04/04/08 21 04/04/08 22 Which Function Grows Faster? Which Function Grows Faster? n3 + 2n2 vs. n3 + 2n2 04/04/08 100n2 + 1000 23 04/04/08 vs. 100n2 + 1000 24 4