SlideShare a Scribd company logo
Amortized Computational Complexity
Abstract : A powerful technique in the complexity analysis of various algorithms is amortization
or averaging over time. Amortized running time is a realistic measure of complexity of a
sequence of operations . It will not provide you with the exact computational time . Instead , it
lets you calculate a tight upper bound and lower bound of algorithms . Based on the result
obtained, varieties of algorithms can be compared for performance analysis . This whitepaper
describes several methods of evaluating amortized complexity .
Introduction : In many uses of data structures , a sequence of operations , rather than a single
operation, is performed . So, the final goal is to evaluate the amortized time complexity of that
sequence . The only requirement is that the sum of the amortized complexity of all elements in
a sequence is greater than the sum of the actual complexities of the elements . So, we can
conclude :
Sum(amortized(i)) >= Sum(actual(i)) ........... (1.1)
Relative to actual cost and amortized cost of an operation in a sequence of n operations , we
define a potential function as below :
P(i) = amortized(i) - actual (i) - P(i-1) ...........(1.2)
Taking sum of the equation , we obtain :
P(n) = Sum(amortized(i)) - Sum(actual(i)) ..........(1.3)
From (1.1) & (1.3) , we conclude :
P(n) >= 0 ........(1.4)
To make the idea of amortization and motivation behind it more concrete , let us consider the
example of evaluating the amortized complexity of an algorithm , which displays number of toys
available in binary format . To update every digit of the display the algorithm takes d unit of
time . Assuming that the number of current toys is N and initial no. of toys is 0, we need to
evaluate the amortized complexity of the algorithm used to display the number of toys . There
are three popular methods to arrive at the amortized complexity of the operations, namely , (1)
aggregate method , (2) accounting method and (3) potential method .
Aggregate Method : In the aggregate method ,we determine the
UpperBoundOnSumOfActualCosts(N) for the sum of the actual costs of the n operations.The
amortized cost is amounted to UpperBoundOnSumOfActualCosts(N) /N .
Let N be the number of toys manufactured ; the number of digits used to display the number of
toys is n or 'Base-2 logN' . The least significant bit of the display has been changed N times ; the
second digit from the right changes once for every 2 toys ; the third digit from the lright changes
once for every 4 times and so on...
So, the aggregate number of digits that have been changed is bounded by n (1+1/2+1/4+...)d or
d2n. So, the amortized cost is amounted to 2n/n = 2d.
Accounting Method : To proceed using accounting method , we must first assign an amortized
cost and then prove that this assignment satisfies eq - (1.1). Generally we start by assigning an
amortized cost obtained by a good guess . Once we have shown this , we obtain an upper bound
on the cost of any operation sequence by computing Sum(f(i)*amortized(i)) , where f(i) be the
frequency of the operation and amortized(i) the amortized cost of the operation .
Suppose , we assign a guessed amortized cost of 2d for each display change . Then the potential
function
P(n) = Sum(amortized(i)) - Sum(actual(i))
= 2dn - d(1+1/2+1/4+.......)
> = 0;
So, the accounting method proved that the amortized cost of the display can be reduced to 2d.
Potential Method : In this approach , we postulate a function for the analysis and use the
function to satisfy eq - (1) .
Consider the example given in the introduction section . When the first toy is available , we can
use the amortized cost 2d to pay for the update , in which d amount is spent and remaining d
amount is retained as a credit to the first digit from the left . Following the update of the second
digit , the amount spent is 2d*2 in which 2d is spent to update two rightmost digits and the
second digit from right now has credit 2d . Proceeding in this way , we can sum up credit on
each digit of the display always equal 2dv , where 2d is the amortized cost and v the value of the
digit. So, we should use the potential function
P(n) = 2d*Sum(v(i)) , where v(i) = digit value of the i-th digit
Let q be the number of 1’s at the rightmost places and the j th display and it has been changed
from jth to (j+1) th no.So, when the display changes from j th to j+1 th value, where j = 1111011
the potential change incurred
P(n) = 2d(1-2*1) ;
So the amortized cost for the display change = actual cost + p(n) = (q+1)d +P(n) = (q+1)d + 2d(1-
2*1).
Conclusion : A worst case analysis ,in which we sum the worst-case time of individual
operations, may be unduly pessimistic ; it ignores correlated effect on data structures. On the
other hand, average case analysis can be inaccurate , as the probabilistic assumptions needed to
carry out the analysis may be false . In such a scenario, amortized analysis , in which we average
the running time over per operation , yield an answer that is both realistic and robust .

More Related Content

What's hot

Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500
ilsamaryum
 

What's hot (18)

09. amortized analysis
09. amortized analysis09. amortized analysis
09. amortized analysis
 
Amortized analysis
Amortized analysisAmortized analysis
Amortized analysis
 
Aoa amortized analysis
Aoa amortized analysisAoa amortized analysis
Aoa amortized analysis
 
Amortized
AmortizedAmortized
Amortized
 
13 Amortized Analysis
13 Amortized Analysis13 Amortized Analysis
13 Amortized Analysis
 
Amortized Analysis
Amortized Analysis Amortized Analysis
Amortized Analysis
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Adauctions
AdauctionsAdauctions
Adauctions
 
12 Greeddy Method
12 Greeddy Method12 Greeddy Method
12 Greeddy Method
 
Nrtl activity coefficient for mixture1
Nrtl activity coefficient for mixture1Nrtl activity coefficient for mixture1
Nrtl activity coefficient for mixture1
 
Synchronous Loadable Up and Down Counter
Synchronous Loadable Up and Down Counter Synchronous Loadable Up and Down Counter
Synchronous Loadable Up and Down Counter
 
Solving a “Transportation Planning” Problem through the Programming Language “C”
Solving a “Transportation Planning” Problem through the Programming Language “C”Solving a “Transportation Planning” Problem through the Programming Language “C”
Solving a “Transportation Planning” Problem through the Programming Language “C”
 
Amortized analysis
Amortized analysisAmortized analysis
Amortized analysis
 
Hw5 2017-spring
Hw5 2017-springHw5 2017-spring
Hw5 2017-spring
 
A star
A starA star
A star
 
Vb scripting
Vb scriptingVb scripting
Vb scripting
 
Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500
 
Topic 1.2
Topic 1.2Topic 1.2
Topic 1.2
 

Viewers also liked

Agile 3.0 - Next Gen Lean Model - Doug Floyd
Agile 3.0 - Next Gen Lean Model - Doug FloydAgile 3.0 - Next Gen Lean Model - Doug Floyd
Agile 3.0 - Next Gen Lean Model - Doug Floyd
dvfloyd
 
2-17-16 Kristen Villareal Resume 2
2-17-16 Kristen Villareal Resume 22-17-16 Kristen Villareal Resume 2
2-17-16 Kristen Villareal Resume 2
Kristen Villareal
 
Learning R via Python…or the other way around
Learning R via Python…or the other way aroundLearning R via Python…or the other way around
Learning R via Python…or the other way around
Sid Xing
 
Reference Letter Nikhil Shahani
Reference Letter Nikhil ShahaniReference Letter Nikhil Shahani
Reference Letter Nikhil Shahani
Nikhil Shahani
 

Viewers also liked (17)

Issue 11 NTEU Chapter_164_newsletter
Issue 11 NTEU Chapter_164_newsletterIssue 11 NTEU Chapter_164_newsletter
Issue 11 NTEU Chapter_164_newsletter
 
Agile 3.0 - Next Gen Lean Model - Doug Floyd
Agile 3.0 - Next Gen Lean Model - Doug FloydAgile 3.0 - Next Gen Lean Model - Doug Floyd
Agile 3.0 - Next Gen Lean Model - Doug Floyd
 
Dielectric parameters of ayurvedic medicines biological approach
Dielectric parameters of ayurvedic medicines biological approachDielectric parameters of ayurvedic medicines biological approach
Dielectric parameters of ayurvedic medicines biological approach
 
Artist's Resume:BIO
Artist's Resume:BIOArtist's Resume:BIO
Artist's Resume:BIO
 
2-17-16 Kristen Villareal Resume 2
2-17-16 Kristen Villareal Resume 22-17-16 Kristen Villareal Resume 2
2-17-16 Kristen Villareal Resume 2
 
Learning R via Python…or the other way around
Learning R via Python…or the other way aroundLearning R via Python…or the other way around
Learning R via Python…or the other way around
 
{py}gradle
{py}gradle{py}gradle
{py}gradle
 
Making HRI accessible 
to everyone
 through 
making hri accesible to everyone...
Making HRI accessible 
to everyone
 through 
making hri accesible to everyone...Making HRI accessible 
to everyone
 through 
making hri accesible to everyone...
Making HRI accessible 
to everyone
 through 
making hri accesible to everyone...
 
Reference Letter Nikhil Shahani
Reference Letter Nikhil ShahaniReference Letter Nikhil Shahani
Reference Letter Nikhil Shahani
 
Python module
Python modulePython module
Python module
 
Java profiling Do It Yourself
Java profiling Do It YourselfJava profiling Do It Yourself
Java profiling Do It Yourself
 
Large partition in Cassandra
Large partition in CassandraLarge partition in Cassandra
Large partition in Cassandra
 
On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cache
 
Java Performance & Profiling
Java Performance & ProfilingJava Performance & Profiling
Java Performance & Profiling
 
PMO - Strategic Model & Concepts Overview
PMO - Strategic Model & Concepts OverviewPMO - Strategic Model & Concepts Overview
PMO - Strategic Model & Concepts Overview
 
IT Project Governance Overview
IT Project Governance OverviewIT Project Governance Overview
IT Project Governance Overview
 
Introduction To HBase
Introduction To HBaseIntroduction To HBase
Introduction To HBase
 

Similar to Amortized complexity

International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
IJERD Editor
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1
Vai Jayanthi
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
Abbas Ali
 
WVKULAK13_submission_14
WVKULAK13_submission_14WVKULAK13_submission_14
WVKULAK13_submission_14
Max De Koninck
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
MAHERMOHAMED27
 
Data Structures - Lecture 8 - Study Notes
Data Structures - Lecture 8 - Study NotesData Structures - Lecture 8 - Study Notes
Data Structures - Lecture 8 - Study Notes
Haitham El-Ghareeb
 

Similar to Amortized complexity (20)

DOC-20230417-WA0013.-7-27.pptx
DOC-20230417-WA0013.-7-27.pptxDOC-20230417-WA0013.-7-27.pptx
DOC-20230417-WA0013.-7-27.pptx
 
5.2 Least Squares Linear Regression.pptx
5.2  Least Squares Linear Regression.pptx5.2  Least Squares Linear Regression.pptx
5.2 Least Squares Linear Regression.pptx
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 
Big Oh.ppt
Big Oh.pptBig Oh.ppt
Big Oh.ppt
 
Asymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CAsymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using C
 
economic load dispatch and unit commitment power_system_operation.pdf
economic load dispatch and unit commitment power_system_operation.pdfeconomic load dispatch and unit commitment power_system_operation.pdf
economic load dispatch and unit commitment power_system_operation.pdf
 
WVKULAK13_submission_14
WVKULAK13_submission_14WVKULAK13_submission_14
WVKULAK13_submission_14
 
Slide2
Slide2Slide2
Slide2
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithms
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1
 
Bellmon Ford Algorithm
Bellmon Ford AlgorithmBellmon Ford Algorithm
Bellmon Ford Algorithm
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
 
Data Structures - Lecture 8 - Study Notes
Data Structures - Lecture 8 - Study NotesData Structures - Lecture 8 - Study Notes
Data Structures - Lecture 8 - Study Notes
 
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
 

Recently uploaded

Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltage
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 

Amortized complexity

  • 1. Amortized Computational Complexity Abstract : A powerful technique in the complexity analysis of various algorithms is amortization or averaging over time. Amortized running time is a realistic measure of complexity of a sequence of operations . It will not provide you with the exact computational time . Instead , it lets you calculate a tight upper bound and lower bound of algorithms . Based on the result obtained, varieties of algorithms can be compared for performance analysis . This whitepaper describes several methods of evaluating amortized complexity . Introduction : In many uses of data structures , a sequence of operations , rather than a single operation, is performed . So, the final goal is to evaluate the amortized time complexity of that sequence . The only requirement is that the sum of the amortized complexity of all elements in a sequence is greater than the sum of the actual complexities of the elements . So, we can conclude : Sum(amortized(i)) >= Sum(actual(i)) ........... (1.1) Relative to actual cost and amortized cost of an operation in a sequence of n operations , we define a potential function as below : P(i) = amortized(i) - actual (i) - P(i-1) ...........(1.2) Taking sum of the equation , we obtain : P(n) = Sum(amortized(i)) - Sum(actual(i)) ..........(1.3) From (1.1) & (1.3) , we conclude : P(n) >= 0 ........(1.4) To make the idea of amortization and motivation behind it more concrete , let us consider the example of evaluating the amortized complexity of an algorithm , which displays number of toys available in binary format . To update every digit of the display the algorithm takes d unit of time . Assuming that the number of current toys is N and initial no. of toys is 0, we need to evaluate the amortized complexity of the algorithm used to display the number of toys . There are three popular methods to arrive at the amortized complexity of the operations, namely , (1) aggregate method , (2) accounting method and (3) potential method .
  • 2. Aggregate Method : In the aggregate method ,we determine the UpperBoundOnSumOfActualCosts(N) for the sum of the actual costs of the n operations.The amortized cost is amounted to UpperBoundOnSumOfActualCosts(N) /N . Let N be the number of toys manufactured ; the number of digits used to display the number of toys is n or 'Base-2 logN' . The least significant bit of the display has been changed N times ; the second digit from the right changes once for every 2 toys ; the third digit from the lright changes once for every 4 times and so on... So, the aggregate number of digits that have been changed is bounded by n (1+1/2+1/4+...)d or d2n. So, the amortized cost is amounted to 2n/n = 2d. Accounting Method : To proceed using accounting method , we must first assign an amortized cost and then prove that this assignment satisfies eq - (1.1). Generally we start by assigning an amortized cost obtained by a good guess . Once we have shown this , we obtain an upper bound on the cost of any operation sequence by computing Sum(f(i)*amortized(i)) , where f(i) be the frequency of the operation and amortized(i) the amortized cost of the operation . Suppose , we assign a guessed amortized cost of 2d for each display change . Then the potential function P(n) = Sum(amortized(i)) - Sum(actual(i)) = 2dn - d(1+1/2+1/4+.......) > = 0; So, the accounting method proved that the amortized cost of the display can be reduced to 2d.
  • 3. Potential Method : In this approach , we postulate a function for the analysis and use the function to satisfy eq - (1) . Consider the example given in the introduction section . When the first toy is available , we can use the amortized cost 2d to pay for the update , in which d amount is spent and remaining d amount is retained as a credit to the first digit from the left . Following the update of the second digit , the amount spent is 2d*2 in which 2d is spent to update two rightmost digits and the second digit from right now has credit 2d . Proceeding in this way , we can sum up credit on each digit of the display always equal 2dv , where 2d is the amortized cost and v the value of the digit. So, we should use the potential function P(n) = 2d*Sum(v(i)) , where v(i) = digit value of the i-th digit Let q be the number of 1’s at the rightmost places and the j th display and it has been changed from jth to (j+1) th no.So, when the display changes from j th to j+1 th value, where j = 1111011 the potential change incurred P(n) = 2d(1-2*1) ; So the amortized cost for the display change = actual cost + p(n) = (q+1)d +P(n) = (q+1)d + 2d(1- 2*1).
  • 4. Conclusion : A worst case analysis ,in which we sum the worst-case time of individual operations, may be unduly pessimistic ; it ignores correlated effect on data structures. On the other hand, average case analysis can be inaccurate , as the probabilistic assumptions needed to carry out the analysis may be false . In such a scenario, amortized analysis , in which we average the running time over per operation , yield an answer that is both realistic and robust .