SlideShare a Scribd company logo
7.3 Analyzing Procedures
By considering the asymptotic growth of functions, rather than their actual
outputs, the OO, ΩΩ, and ΘΘ operators allow us to hide constants and factors
that change
depending on the speed of our processor, how data is arranged in memory, and
the specifics of how our interpreter is implemented.
Instead, we can consider the essential properties of how the running time of the
procedures increases with the size of the input.
7.3.1 Input size
Procedure inputs may be many different types: Numbers, Lists of Numbers, Lists
of Lists, Procedures, etc.
Our goal is to characterize the input size with a single number that does not depend on
the types of the input.
We use the Turing machine to model a computer, so the way to measure the size of the
input is the number of characters needed to write the input on the tape.
The characters can be from any fixed-size alphabet, such as the ten decimal digits, or the
letters of the alphabet.
The number of different symbols in the tape alphabet does not matter for our analysis
since we are concerned with orders of growth not absolute values. Within the OO, ΩΩ,
and ΘΘ operators, a constant factor does not matter
(e.g., Θ(n)≡Θ(17n+523)Θ(n)≡Θ(17n+523)).
This means is doesn't matter whether we use an alphabet with two symbols or
an alphabet with 256 symbols.
With two symbols the input may be 8 times as long as it is with a 256-symbol alphabet,
but the constant factor does not matter inside the asymptotic operator.
Thus, we measure the size of the input as the number of symbols required to write the
number on a Turing Machine input tape.
To figure out the input size of a given type, we need to think about how many symbols it
would require to write down inputs of that type.
Booleans. There are only two Boolean values: true and false. Hence, the length of
a Boolean input is fixed.
Numbers. Using the decimal number system (that is, 10 tape symbols), we can write a
number of magnitude nn using log10nlog10⁡n digits.
Using the binary number system (that is, 2 tape symbols), we can write it
using log2nlog2⁡n bits. Within the asymptotic operators, the base of the
logarithm
does not matter (as long as it is a constant) since it changes the result by a
constant factor.
We can see this from the argument above --- changing the number of symbols in
the input alphabet changes the input length by a constant factor which has no impact
within the asymptotic operators.
Lists. If the input is a List, the size of the input is related to the number of elements in
the list.
If each element is a constant size (for example, a list of numbers where each number is
between 0 and 100), the size of the input list is some constant multiple of the number of
elements in the list.
Hence, the size of an input that is a list of nn elements is cncn for some constant
cc. Since Θ(cn)=Θ(n)Θ(cn)=Θ(n), the size of a List input is Θ(n)Θ(n) where nn
is the
number of elements in the List.
If List elements can vary in size, then we need to account for that in the input size. For
example, suppose the input is a List of Lists, where there are nn elements in each inner
List, and there are nn List elements in the main List.
Then, there are n2n2 total elements and the input size is in Θ(n2)Θ(n2).
7.3.2 Running Time
We want a measure of the running time of a procedure that satisfies two properties: (1)
it should be robust to ephemeral properties of a particular execution or computer, and
(2) it should provide insights into how long it takes evaluate the procedure on a wide
range of inputs.
To estimate the running time of an evaluation, we use the number of steps required to
perform the evaluation.
The actual number of steps depends on the details of how much work can be done on
each step. For any particular processor, both the time it takes to perform a step and the
amount of work that can be done in one step varies.
When we analyze procedures, however, we usually don't want to deal with these details.
Instead, what we care about is how the running time changes as the input size increases.
This means we can count anything we want as a "step" as long as each step is
the approximately same size and the time a step requires does not depend on the size of
the input.
The clearest and simplest definition of a step is to use one Turing Machine step.
We have a precise definition of exactly what a Turing Machine can do in one
step: it can read the symbol in the current square, write a symbol into that
square, transition its internal state number, and move one square to the left or right.
Counting Turing Machine steps is very precise, but difficult because we do not usually
start with a Turing Machine description of a procedure and creating one is tedious.
Time makes more converts than reason. -- Thomas Paine
Instead, we usually reason directly from a Scheme procedure (or any precise description
of a procedure) using larger steps.
As long as we can claim that whatever we consider a step could be simulated using a
constant number of steps on a Turing Machine, our larger steps will produce the same
answer within the asymptotic operators. One possibility is to count the number of times
an evaluation rule is used in an evaluation of an application of the procedure.
The amount of work in each evaluation rule may vary slightly (for example, the
evaluation rule for an if expression seems more complex than the rule for a primitive)
but does not depend on the input size.
Hence, it is reasonable to assume all the evaluation rules to take constant time.
This does not include any additional evaluation rules that are needed to apply one rule.
For example, the evaluation rule for application expressions includes evaluating every
subexpression. Evaluating an application constitutes one work unit for the application
rule itself, plus all the work required to evaluate the subexpressions.
In cases where the bigger steps are unclear, we can always return to our precise
definition of a step as one step of a Turing Machine.
7.3.3 Worst Case Input
A procedure may have different running times for inputs of the same
size.
For example, consider this procedure that takes a List as input and outputs the
first positive number in the list:
(if (> (car p) 0) (car p) (list-first-pos (cdr p)))))
If the first element in the input list is positive, evaluating the application of list-
first- pos requires very little work.
It is not necessary to consider any other elements in the list if the first element
is positive.
On the other hand, if none of the elements are positive, the procedure needs to test each
element in the list until it reaches the end of the list (where the base case reports an
error).
In our analyses we usually consider the worst case input. For a given size, the worst case
input is the input for which evaluating the procedure takes the most work.
By focusing on the worst case input, we know the maximum running time for
the procedure. Without knowing something about the possible inputs to the procedure,
it is safest to be pessimistic about the input and not assume any properties that
are not known (such as that the first number in the list is positive for the first-pos
example).
(define (list-first-pos p)
(if (null? p) (error "No positive element found")
In some cases, we also consider the average case input. Since most procedures can take
infinitely many inputs, this requires understanding the distribution of possible inputs to
determine an "average" input.
This is often necessary when we are analyzing the running time of a procedure that uses
another helper procedure. If we use the worst-case running time for the helper
procedure, we will grossly overestimate the running time of the main procedure.
Instead, since we know how the main procedure uses the helper procedure, we can more
precisely estimate the actual running time by considering the actual inputs. We see an
example of this in the analysis of how the + procedure is used by list-length in
Section 7.4.2.

More Related Content

Viewers also liked

Tổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCM
Tổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCMTổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCM
Tổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCMTien Thao
 
Diez tips mejorarestudioonline
Diez tips mejorarestudioonlineDiez tips mejorarestudioonline
Diez tips mejorarestudioonlineCarmen Rodriguez
 
Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...
Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...
Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...Tien Thao
 
Xvii Islahat
Xvii IslahatXvii Islahat
Xvii IslahatBigBoss
 
replacement grammars
replacement grammarsreplacement grammars
replacement grammarsRajendran
 
Las relaciones de los seres vivos Gonzalez y Fiorotto
Las relaciones de los seres vivos  Gonzalez y FiorottoLas relaciones de los seres vivos  Gonzalez y Fiorotto
Las relaciones de los seres vivos Gonzalez y FiorottoClaudia Poza
 
Relaciones entre los seres vivos zuazo fiorotto-alejo
Relaciones entre los seres vivos  zuazo fiorotto-alejoRelaciones entre los seres vivos  zuazo fiorotto-alejo
Relaciones entre los seres vivos zuazo fiorotto-alejoClaudia Poza
 
Thư giãn
Thư giãnThư giãn
Thư giãnHa Hoa
 

Viewers also liked (17)

Tổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCM
Tổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCMTổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCM
Tổ chức sự kiện chuyên nghiệp, cho thuê âm thanh ánh sáng chất lượng tại TPHCM
 
.
..
.
 
Gráfico1
Gráfico1Gráfico1
Gráfico1
 
Diez tips mejorarestudioonline
Diez tips mejorarestudioonlineDiez tips mejorarestudioonline
Diez tips mejorarestudioonline
 
Badpresentation
BadpresentationBadpresentation
Badpresentation
 
ZEESHAN cv
ZEESHAN cvZEESHAN cv
ZEESHAN cv
 
Tsunamis
TsunamisTsunamis
Tsunamis
 
Los t ic s
Los t ic sLos t ic s
Los t ic s
 
信息 Sunday Sermon 03/07/2011
信息 Sunday Sermon 03/07/2011信息 Sunday Sermon 03/07/2011
信息 Sunday Sermon 03/07/2011
 
Sadic cv new
Sadic cv newSadic cv new
Sadic cv new
 
Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...
Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...
Những công ty tổ chức khai trương, khởi công, động thổ chuyên nghiệp nhất tại...
 
Xvii Islahat
Xvii IslahatXvii Islahat
Xvii Islahat
 
replacement grammars
replacement grammarsreplacement grammars
replacement grammars
 
2.ecología
2.ecología2.ecología
2.ecología
 
Las relaciones de los seres vivos Gonzalez y Fiorotto
Las relaciones de los seres vivos  Gonzalez y FiorottoLas relaciones de los seres vivos  Gonzalez y Fiorotto
Las relaciones de los seres vivos Gonzalez y Fiorotto
 
Relaciones entre los seres vivos zuazo fiorotto-alejo
Relaciones entre los seres vivos  zuazo fiorotto-alejoRelaciones entre los seres vivos  zuazo fiorotto-alejo
Relaciones entre los seres vivos zuazo fiorotto-alejo
 
Thư giãn
Thư giãnThư giãn
Thư giãn
 

Similar to analyzing procedures

9 big o-notation
9 big o-notation9 big o-notation
9 big o-notationirdginfo
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfMemMem25
 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptxSayanSen36
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Performance analysis and randamized agoritham
Performance analysis and randamized agorithamPerformance analysis and randamized agoritham
Performance analysis and randamized agorithamlilyMalar1
 
Theory of algorithms final
Theory of algorithms final Theory of algorithms final
Theory of algorithms final Dgech
 
Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsVivek Bhargav
 
Slides [DAA] Unit 2 Ch 2.pdf
Slides [DAA] Unit 2 Ch 2.pdfSlides [DAA] Unit 2 Ch 2.pdf
Slides [DAA] Unit 2 Ch 2.pdfVijayraj799513
 
Analysis and Algorithms: basic Introduction
Analysis and Algorithms: basic IntroductionAnalysis and Algorithms: basic Introduction
Analysis and Algorithms: basic Introductionssuseraf8b2f
 
Asymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxAsymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxRachit Jain
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...AntareepMajumder
 

Similar to analyzing procedures (20)

9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptx
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Performance analysis and randamized agoritham
Performance analysis and randamized agorithamPerformance analysis and randamized agoritham
Performance analysis and randamized agoritham
 
Theory of algorithms final
Theory of algorithms final Theory of algorithms final
Theory of algorithms final
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithms
 
Analyzing algorithms
Analyzing algorithmsAnalyzing algorithms
Analyzing algorithms
 
Slides [DAA] Unit 2 Ch 2.pdf
Slides [DAA] Unit 2 Ch 2.pdfSlides [DAA] Unit 2 Ch 2.pdf
Slides [DAA] Unit 2 Ch 2.pdf
 
Analysis and Algorithms: basic Introduction
Analysis and Algorithms: basic IntroductionAnalysis and Algorithms: basic Introduction
Analysis and Algorithms: basic Introduction
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Asymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxAsymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptx
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_25-07-2022_Fu...
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Complexity
ComplexityComplexity
Complexity
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 

More from Rajendran

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower boundsRajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsRajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower boundsRajendran
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statisticsRajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theoremRajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree methodRajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theoremRajendran
 
Master method
Master method Master method
Master method Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithmsRajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisRajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisRajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of QuicksortRajendran
 
Np completeness
Np completenessNp completeness
Np completenessRajendran
 
computer languages
computer languagescomputer languages
computer languagesRajendran
 

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hash table
Hash tableHash table
Hash table
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method
Master method Master method
Master method
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 

Recently uploaded

UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
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.pdfTamralipta Mahavidyalaya
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfDr. M. Kumaresan Hort.
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXMIRIAMSALINAS13
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 
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 costumersPedroFerreira53928
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 

Recently uploaded (20)

UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
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
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
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
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 

analyzing procedures

  • 1. 7.3 Analyzing Procedures By considering the asymptotic growth of functions, rather than their actual outputs, the OO, ΩΩ, and ΘΘ operators allow us to hide constants and factors that change depending on the speed of our processor, how data is arranged in memory, and the specifics of how our interpreter is implemented. Instead, we can consider the essential properties of how the running time of the procedures increases with the size of the input. 7.3.1 Input size Procedure inputs may be many different types: Numbers, Lists of Numbers, Lists of Lists, Procedures, etc. Our goal is to characterize the input size with a single number that does not depend on the types of the input. We use the Turing machine to model a computer, so the way to measure the size of the input is the number of characters needed to write the input on the tape. The characters can be from any fixed-size alphabet, such as the ten decimal digits, or the letters of the alphabet. The number of different symbols in the tape alphabet does not matter for our analysis since we are concerned with orders of growth not absolute values. Within the OO, ΩΩ, and ΘΘ operators, a constant factor does not matter (e.g., Θ(n)≡Θ(17n+523)Θ(n)≡Θ(17n+523)).
  • 2. This means is doesn't matter whether we use an alphabet with two symbols or an alphabet with 256 symbols. With two symbols the input may be 8 times as long as it is with a 256-symbol alphabet, but the constant factor does not matter inside the asymptotic operator. Thus, we measure the size of the input as the number of symbols required to write the number on a Turing Machine input tape. To figure out the input size of a given type, we need to think about how many symbols it would require to write down inputs of that type. Booleans. There are only two Boolean values: true and false. Hence, the length of a Boolean input is fixed. Numbers. Using the decimal number system (that is, 10 tape symbols), we can write a number of magnitude nn using log10nlog10⁡n digits. Using the binary number system (that is, 2 tape symbols), we can write it using log2nlog2⁡n bits. Within the asymptotic operators, the base of the logarithm does not matter (as long as it is a constant) since it changes the result by a constant factor. We can see this from the argument above --- changing the number of symbols in the input alphabet changes the input length by a constant factor which has no impact within the asymptotic operators.
  • 3. Lists. If the input is a List, the size of the input is related to the number of elements in the list. If each element is a constant size (for example, a list of numbers where each number is between 0 and 100), the size of the input list is some constant multiple of the number of elements in the list. Hence, the size of an input that is a list of nn elements is cncn for some constant cc. Since Θ(cn)=Θ(n)Θ(cn)=Θ(n), the size of a List input is Θ(n)Θ(n) where nn is the number of elements in the List. If List elements can vary in size, then we need to account for that in the input size. For example, suppose the input is a List of Lists, where there are nn elements in each inner List, and there are nn List elements in the main List. Then, there are n2n2 total elements and the input size is in Θ(n2)Θ(n2).
  • 4. 7.3.2 Running Time We want a measure of the running time of a procedure that satisfies two properties: (1) it should be robust to ephemeral properties of a particular execution or computer, and (2) it should provide insights into how long it takes evaluate the procedure on a wide range of inputs. To estimate the running time of an evaluation, we use the number of steps required to perform the evaluation. The actual number of steps depends on the details of how much work can be done on each step. For any particular processor, both the time it takes to perform a step and the amount of work that can be done in one step varies. When we analyze procedures, however, we usually don't want to deal with these details. Instead, what we care about is how the running time changes as the input size increases. This means we can count anything we want as a "step" as long as each step is the approximately same size and the time a step requires does not depend on the size of the input. The clearest and simplest definition of a step is to use one Turing Machine step. We have a precise definition of exactly what a Turing Machine can do in one step: it can read the symbol in the current square, write a symbol into that square, transition its internal state number, and move one square to the left or right.
  • 5. Counting Turing Machine steps is very precise, but difficult because we do not usually start with a Turing Machine description of a procedure and creating one is tedious. Time makes more converts than reason. -- Thomas Paine Instead, we usually reason directly from a Scheme procedure (or any precise description of a procedure) using larger steps. As long as we can claim that whatever we consider a step could be simulated using a constant number of steps on a Turing Machine, our larger steps will produce the same answer within the asymptotic operators. One possibility is to count the number of times an evaluation rule is used in an evaluation of an application of the procedure. The amount of work in each evaluation rule may vary slightly (for example, the evaluation rule for an if expression seems more complex than the rule for a primitive) but does not depend on the input size. Hence, it is reasonable to assume all the evaluation rules to take constant time. This does not include any additional evaluation rules that are needed to apply one rule. For example, the evaluation rule for application expressions includes evaluating every subexpression. Evaluating an application constitutes one work unit for the application rule itself, plus all the work required to evaluate the subexpressions. In cases where the bigger steps are unclear, we can always return to our precise definition of a step as one step of a Turing Machine.
  • 6. 7.3.3 Worst Case Input A procedure may have different running times for inputs of the same size. For example, consider this procedure that takes a List as input and outputs the first positive number in the list: (if (> (car p) 0) (car p) (list-first-pos (cdr p))))) If the first element in the input list is positive, evaluating the application of list- first- pos requires very little work. It is not necessary to consider any other elements in the list if the first element is positive. On the other hand, if none of the elements are positive, the procedure needs to test each element in the list until it reaches the end of the list (where the base case reports an error). In our analyses we usually consider the worst case input. For a given size, the worst case input is the input for which evaluating the procedure takes the most work. By focusing on the worst case input, we know the maximum running time for the procedure. Without knowing something about the possible inputs to the procedure, it is safest to be pessimistic about the input and not assume any properties that are not known (such as that the first number in the list is positive for the first-pos example). (define (list-first-pos p) (if (null? p) (error "No positive element found")
  • 7. In some cases, we also consider the average case input. Since most procedures can take infinitely many inputs, this requires understanding the distribution of possible inputs to determine an "average" input. This is often necessary when we are analyzing the running time of a procedure that uses another helper procedure. If we use the worst-case running time for the helper procedure, we will grossly overestimate the running time of the main procedure. Instead, since we know how the main procedure uses the helper procedure, we can more precisely estimate the actual running time by considering the actual inputs. We see an example of this in the analysis of how the + procedure is used by list-length in Section 7.4.2.