SlideShare a Scribd company logo
Class 18:
    Measuring
    Cost



                                                cs1120 Fall 2011
                                                David Evans
Colossus Rebuilt, Bletchley Park, Summer 2004   3 October 2011
Plan
How Computer Scientists Measure Cost
Asymptotic Operators


         Assistant Coaches’ Review Sessions for Exam 1:
             Tuesday (tomorrow), 6:30pm, Rice 442
                 Wednesday, 7:30pm, Rice 442




                                                          2
(define (fibo-rec n)                   (define (fibo-loop n)
    (if (= n 0) 0                          (cdr
        (if (= n 1) 1                       (loop 1 (cons 0 1) (lambda (i) (< i n)) inc
            (+ (fibo-rec (- n 1))                 (lambda (i v)
               (fibo-rec (- n 2))))))               (cons (cdr v) (+ (car v) (cdr v)))))))

> (time (fibo-rec 2))                         > (time (fibo-loop 2))
cpu time: 0 real time: 0 gc time: 0           cpu time: 0 real time: 0 gc time: 0
1                                             1
> (time (fibo-rec 5))                         > (time (fibo-loop 5))
cpu time: 0 real time: 0 gc time: 0           cpu time: 0 real time: 0 gc time: 0
5                                             5
> (time (fibo-rec 20))                        > (time (fibo-loop 20))
cpu time: 0 real time: 2 gc time: 0           cpu time: 0 real time: 0 gc time: 0
6765                                          6765
> (time (fibo-rec 30))                        > (time (fibo-loop 30))
cpu time: 359 real time: 370 gc time: 0       cpu time: 0 real time: 0 gc time: 0
832040                                        832040
> (time (fibo-rec 60))                        > (time (fibo-loop 60))
still waiting since Friday…                   cpu time: 0 real time: 0 gc time: 0
                                              1548008755920
(define (fibo-rec n)                 (define (fibo-loop n)
  (if (= n 0) 0                        (cdr
      (if (= n 1) 1                     (loop 1 (cons 0 1)
          (+ (fibo-rec (- n 1))               (lambda (i) (< i n)) inc
             (fibo-rec (- n 2))))))           (lambda (i v)
                                                (cons (cdr v) (+ (car v) (cdr v)))))))

Number of “expensive” calls:                 Number of “expensive” calls:




where n is the value of the input,
and is the “golden ratio”:
How Computer Scientists
                    Measure Cost
 Abstract: hide all the details that will change
  when you get your next laptop to capture the
  fundamental cost of the procedure
    Cost: number of steps for a Turing Machine to
        execute the procedure
 Order of Growth: what matters is how the cost
  scales with the size of the input
    Size of input: how many TM squares needed to
        represent it
Usually, we can determine these without actually writing a TM version of our procedure!

                                                                                          5
Orders of Growth
                   6
Asymptotic Operators




                       7
Asymptotic Operators

These notations define sets of functions


In computing, the function inside the operator is
(usually) a mapping from the size of the input to the
number of steps required. We use the asymptotic
operators to abstract away all the silly details about
particular computers.

                                                         8
Big O
Intuition: the set of functions that grow no
  faster than f (more formal definition soon)
Asymptotic growth rate: as input to f approaches
  infinity, how fast does value of f increase
  Hence, only the fastest-growing term in f matters.


                                ?
           ?
                                                       9
Examples
              O(n3)               f(n) = 12n2 + n

                          O(n2)
f(n) = n2.5




 f(n) = n3.1 – n2

                                                10
Formal Definition




                    11
O Examples




x O (x2)?
10x O (x)?
x2   O (x)?


                       12
Lower Bound:          (Omega)




         Only difference from O: this was


                                            13
Where is
 (n2)?
              O(n3)                  f(n) = 12n2 + n

                             O(n2)
f(n) = n2.5           (n2)




 f(n) = n3.1 – n2

                                                   14
Inside-Out
                (n3)                  f(n) = 12n2 + n

                               (n2)
f(n) = n2.5            O(n2)




 f(n) = n3.1 – n2

                                                    15
Recap
Big-O: functions that grow no faster than f




Omega ( ): functions that grow no slower than f




                                                  16
The Sets O(f ) and Ω(f )

                O(f)   Ω(f) Functions
    Functions                that grow
    that grow                no slower
    no faster            f   than f
    than f




                                         17
What else might be useful?

              O(n3)                  f(n) = 12n2 + n

                             O(n2)
f(n) = n2.5           (n2)




 f(n) = n3.1 – n2

                                                   18
Theta (“Order of”)
Intuition: set of functions that grow as fast as f

Definition:




Slang: When people say, “f is order g” that means


                                                     19
Tight Bound Theta ( )
              O(n3)                  f(n) = 12n2 + n

                             O(n2)
f(n) = n2.5           (n2)
                                     (n2)



 f(n) = n3.1 – n2             Faster Growing

                                                   20
Θ Examples
Is 10n in Θ(n)?
   Yes, since 10n is (n) and 10n is in O(n)
      Doesn’t matter that you choose different c values
        for each part; they are independent
Is n2 in Θ(n)?
    No, since n2 is not in O(n)
 Is n in Θ(n2)?
    No, since n2 is not in (n)


                                                          21
The Sets O(f ), Ω(f ), and Θ(f )

                                   O(f)   Ω(f) Functions
                     Functions                  that grow
                     that grow                  no slower
                     no faster              f   than f
                     than f




          Θ(f)


How big are O(f ), Ω(f ), and Θ(f )?

                                                            22
Summary
Big-O: grow no faster than f
Omega: grow no slower than f
Theta:


  Which of these would we most like to know about
    costproc(n) = number of steps to execute proc on
                     input of size n
  ?


                                                       23
Complexity of Problems
       So, why do we need O and Ω?

Computer scientists often care about the
complexity of problems not algorithms. The
complexity of a problem is the complexity of the
best possible algorithm that solves the problem.



                                                   24
Algorithm Analysis
What is the asymptotic running time of the
Scheme procedure below:

    (define (bigger a b)
      (if (> a b) a b))




                                             25
Charge
Next class:
analyzing the costs of bigger
analyzing the costs of brute-force-lorenz

     Assistant Coaches’ Review Sessions for Exam 1:
         Tuesday (tomorrow), 6:30pm, Rice 442
             Wednesday, 7:30pm, Rice 442




                                                      26

More Related Content

What's hot

Faster Practical Block Compression for Rank/Select Dictionaries
Faster Practical Block Compression for Rank/Select DictionariesFaster Practical Block Compression for Rank/Select Dictionaries
Faster Practical Block Compression for Rank/Select Dictionaries
Rakuten Group, Inc.
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
Andrey Karpov
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
shin
 
Codes and Isogenies
Codes and IsogeniesCodes and Isogenies
Codes and Isogenies
Priyanka Aash
 
Yampa AFRP Introduction
Yampa AFRP IntroductionYampa AFRP Introduction
Yampa AFRP Introduction
ChengHui Weng
 
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
Alex Pruden
 
2020 겨울방학 정기스터디 3주차
2020 겨울방학 정기스터디 3주차2020 겨울방학 정기스터디 3주차
2020 겨울방학 정기스터디 3주차
Moonki Choi
 
A verifiable random function with short proofs and keys
A verifiable random function with short proofs and keysA verifiable random function with short proofs and keys
A verifiable random function with short proofs and keysAleksandr Yampolskiy
 
2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차
Moonki Choi
 
Compilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVMCompilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVM
Linaro
 
ZK Study Club: Sumcheck Arguments and Their Applications
ZK Study Club: Sumcheck Arguments and Their ApplicationsZK Study Club: Sumcheck Arguments and Their Applications
ZK Study Club: Sumcheck Arguments and Their Applications
Alex Pruden
 
Improved security system using steganography and elliptic curve crypto...
Improved  security  system using  steganography  and  elliptic  curve  crypto...Improved  security  system using  steganography  and  elliptic  curve  crypto...
Improved security system using steganography and elliptic curve crypto...
atanuanwesha
 
The Uncertain Enterprise
The Uncertain EnterpriseThe Uncertain Enterprise
The Uncertain Enterprise
ClarkTony
 
8086 labmanual
8086 labmanual8086 labmanual
8086 labmanualiravi9
 
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle ModelzkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
Alex Pruden
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。
Mr. Vengineer
 
Python grass
Python grassPython grass
Python grass
Margherita Di Leo
 
Program implementation and testing
Program implementation and testingProgram implementation and testing
Program implementation and testing
abukky52
 
Introduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionIntroduction to Homomorphic Encryption
Introduction to Homomorphic Encryption
Christoph Matthies
 
Computing on Encrypted Data
Computing on Encrypted DataComputing on Encrypted Data
Computing on Encrypted Data
New York Technology Council
 

What's hot (20)

Faster Practical Block Compression for Rank/Select Dictionaries
Faster Practical Block Compression for Rank/Select DictionariesFaster Practical Block Compression for Rank/Select Dictionaries
Faster Practical Block Compression for Rank/Select Dictionaries
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
 
Codes and Isogenies
Codes and IsogeniesCodes and Isogenies
Codes and Isogenies
 
Yampa AFRP Introduction
Yampa AFRP IntroductionYampa AFRP Introduction
Yampa AFRP Introduction
 
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
 
2020 겨울방학 정기스터디 3주차
2020 겨울방학 정기스터디 3주차2020 겨울방학 정기스터디 3주차
2020 겨울방학 정기스터디 3주차
 
A verifiable random function with short proofs and keys
A verifiable random function with short proofs and keysA verifiable random function with short proofs and keys
A verifiable random function with short proofs and keys
 
2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차
 
Compilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVMCompilation of COSMO for GPU using LLVM
Compilation of COSMO for GPU using LLVM
 
ZK Study Club: Sumcheck Arguments and Their Applications
ZK Study Club: Sumcheck Arguments and Their ApplicationsZK Study Club: Sumcheck Arguments and Their Applications
ZK Study Club: Sumcheck Arguments and Their Applications
 
Improved security system using steganography and elliptic curve crypto...
Improved  security  system using  steganography  and  elliptic  curve  crypto...Improved  security  system using  steganography  and  elliptic  curve  crypto...
Improved security system using steganography and elliptic curve crypto...
 
The Uncertain Enterprise
The Uncertain EnterpriseThe Uncertain Enterprise
The Uncertain Enterprise
 
8086 labmanual
8086 labmanual8086 labmanual
8086 labmanual
 
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle ModelzkStudy Club: Subquadratic SNARGs in the Random Oracle Model
zkStudy Club: Subquadratic SNARGs in the Random Oracle Model
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。
 
Python grass
Python grassPython grass
Python grass
 
Program implementation and testing
Program implementation and testingProgram implementation and testing
Program implementation and testing
 
Introduction to Homomorphic Encryption
Introduction to Homomorphic EncryptionIntroduction to Homomorphic Encryption
Introduction to Homomorphic Encryption
 
Computing on Encrypted Data
Computing on Encrypted DataComputing on Encrypted Data
Computing on Encrypted Data
 

Similar to Class 18: Measuring Cost

Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
YekoyeTigabuYeko
 
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
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
pallavidhade2
 
algorithm_analysis1
algorithm_analysis1algorithm_analysis1
algorithm_analysis1
Mohamed Elsayed
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
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
 
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
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptx
MouDhara1
 
Algorithms - Rocksolid Tour 2013
Algorithms  - Rocksolid Tour 2013Algorithms  - Rocksolid Tour 2013
Algorithms - Rocksolid Tour 2013Gary Short
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexityashishtinku
 
Class 17: Golden Sneezewort
Class 17: Golden SneezewortClass 17: Golden Sneezewort
Class 17: Golden Sneezewort
David Evans
 
Lec1
Lec1Lec1
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Time complexity
Time complexityTime complexity
Time complexity
LAKSHMITHARUN PONNAM
 
AlgorithmAnalysis2.ppt
AlgorithmAnalysis2.pptAlgorithmAnalysis2.ppt
AlgorithmAnalysis2.ppt
REMEGIUSPRAVEENSAHAY
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexityAbbas Ali
 

Similar to Class 18: Measuring Cost (20)

Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Analysis of algo
Analysis of algoAnalysis of algo
Analysis of algo
 
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
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
algorithm_analysis1
algorithm_analysis1algorithm_analysis1
algorithm_analysis1
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.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
 
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
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptx
 
Algorithms - Rocksolid Tour 2013
Algorithms  - Rocksolid Tour 2013Algorithms  - Rocksolid Tour 2013
Algorithms - Rocksolid Tour 2013
 
big_oh
big_ohbig_oh
big_oh
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexity
 
Class 17: Golden Sneezewort
Class 17: Golden SneezewortClass 17: Golden Sneezewort
Class 17: Golden Sneezewort
 
Lec1
Lec1Lec1
Lec1
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Time complexity
Time complexityTime complexity
Time complexity
 
AlgorithmAnalysis2.ppt
AlgorithmAnalysis2.pptAlgorithmAnalysis2.ppt
AlgorithmAnalysis2.ppt
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 

More from David Evans

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
David Evans
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
David Evans
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
David Evans
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
David Evans
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
David Evans
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
David Evans
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
David Evans
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
David Evans
 
Mining
MiningMining
Mining
David Evans
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
David Evans
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
David Evans
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
David Evans
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
David Evans
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
David Evans
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
David Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
David Evans
 
Silk Road
Silk RoadSilk Road
Silk Road
David Evans
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
David Evans
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
David Evans
 

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Recently uploaded

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

Class 18: Measuring Cost

  • 1. Class 18: Measuring Cost cs1120 Fall 2011 David Evans Colossus Rebuilt, Bletchley Park, Summer 2004 3 October 2011
  • 2. Plan How Computer Scientists Measure Cost Asymptotic Operators Assistant Coaches’ Review Sessions for Exam 1: Tuesday (tomorrow), 6:30pm, Rice 442 Wednesday, 7:30pm, Rice 442 2
  • 3. (define (fibo-rec n) (define (fibo-loop n) (if (= n 0) 0 (cdr (if (= n 1) 1 (loop 1 (cons 0 1) (lambda (i) (< i n)) inc (+ (fibo-rec (- n 1)) (lambda (i v) (fibo-rec (- n 2)))))) (cons (cdr v) (+ (car v) (cdr v))))))) > (time (fibo-rec 2)) > (time (fibo-loop 2)) cpu time: 0 real time: 0 gc time: 0 cpu time: 0 real time: 0 gc time: 0 1 1 > (time (fibo-rec 5)) > (time (fibo-loop 5)) cpu time: 0 real time: 0 gc time: 0 cpu time: 0 real time: 0 gc time: 0 5 5 > (time (fibo-rec 20)) > (time (fibo-loop 20)) cpu time: 0 real time: 2 gc time: 0 cpu time: 0 real time: 0 gc time: 0 6765 6765 > (time (fibo-rec 30)) > (time (fibo-loop 30)) cpu time: 359 real time: 370 gc time: 0 cpu time: 0 real time: 0 gc time: 0 832040 832040 > (time (fibo-rec 60)) > (time (fibo-loop 60)) still waiting since Friday… cpu time: 0 real time: 0 gc time: 0 1548008755920
  • 4. (define (fibo-rec n) (define (fibo-loop n) (if (= n 0) 0 (cdr (if (= n 1) 1 (loop 1 (cons 0 1) (+ (fibo-rec (- n 1)) (lambda (i) (< i n)) inc (fibo-rec (- n 2)))))) (lambda (i v) (cons (cdr v) (+ (car v) (cdr v))))))) Number of “expensive” calls: Number of “expensive” calls: where n is the value of the input, and is the “golden ratio”:
  • 5. How Computer Scientists Measure Cost Abstract: hide all the details that will change when you get your next laptop to capture the fundamental cost of the procedure Cost: number of steps for a Turing Machine to execute the procedure Order of Growth: what matters is how the cost scales with the size of the input Size of input: how many TM squares needed to represent it Usually, we can determine these without actually writing a TM version of our procedure! 5
  • 8. Asymptotic Operators These notations define sets of functions In computing, the function inside the operator is (usually) a mapping from the size of the input to the number of steps required. We use the asymptotic operators to abstract away all the silly details about particular computers. 8
  • 9. Big O Intuition: the set of functions that grow no faster than f (more formal definition soon) Asymptotic growth rate: as input to f approaches infinity, how fast does value of f increase Hence, only the fastest-growing term in f matters. ? ? 9
  • 10. Examples O(n3) f(n) = 12n2 + n O(n2) f(n) = n2.5 f(n) = n3.1 – n2 10
  • 12. O Examples x O (x2)? 10x O (x)? x2 O (x)? 12
  • 13. Lower Bound: (Omega) Only difference from O: this was 13
  • 14. Where is (n2)? O(n3) f(n) = 12n2 + n O(n2) f(n) = n2.5 (n2) f(n) = n3.1 – n2 14
  • 15. Inside-Out (n3) f(n) = 12n2 + n (n2) f(n) = n2.5 O(n2) f(n) = n3.1 – n2 15
  • 16. Recap Big-O: functions that grow no faster than f Omega ( ): functions that grow no slower than f 16
  • 17. The Sets O(f ) and Ω(f ) O(f) Ω(f) Functions Functions that grow that grow no slower no faster f than f than f 17
  • 18. What else might be useful? O(n3) f(n) = 12n2 + n O(n2) f(n) = n2.5 (n2) f(n) = n3.1 – n2 18
  • 19. Theta (“Order of”) Intuition: set of functions that grow as fast as f Definition: Slang: When people say, “f is order g” that means 19
  • 20. Tight Bound Theta ( ) O(n3) f(n) = 12n2 + n O(n2) f(n) = n2.5 (n2) (n2) f(n) = n3.1 – n2 Faster Growing 20
  • 21. Θ Examples Is 10n in Θ(n)? Yes, since 10n is (n) and 10n is in O(n) Doesn’t matter that you choose different c values for each part; they are independent Is n2 in Θ(n)? No, since n2 is not in O(n) Is n in Θ(n2)? No, since n2 is not in (n) 21
  • 22. The Sets O(f ), Ω(f ), and Θ(f ) O(f) Ω(f) Functions Functions that grow that grow no slower no faster f than f than f Θ(f) How big are O(f ), Ω(f ), and Θ(f )? 22
  • 23. Summary Big-O: grow no faster than f Omega: grow no slower than f Theta: Which of these would we most like to know about costproc(n) = number of steps to execute proc on input of size n ? 23
  • 24. Complexity of Problems So, why do we need O and Ω? Computer scientists often care about the complexity of problems not algorithms. The complexity of a problem is the complexity of the best possible algorithm that solves the problem. 24
  • 25. Algorithm Analysis What is the asymptotic running time of the Scheme procedure below: (define (bigger a b) (if (> a b) a b)) 25
  • 26. Charge Next class: analyzing the costs of bigger analyzing the costs of brute-force-lorenz Assistant Coaches’ Review Sessions for Exam 1: Tuesday (tomorrow), 6:30pm, Rice 442 Wednesday, 7:30pm, Rice 442 26