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

RTF
Amortized complexity
RTF
Amortized complexity
RTF
Amortized complexity
RTF
Amortized complexity
RTF
Amortized complexity
RTF
Amortized complexity
RTF
Amortized complexity
PPT
Amortized Analysis of Algorithms
Amortized complexity
Amortized complexity
Amortized complexity
Amortized complexity
Amortized complexity
Amortized complexity
Amortized complexity
Amortized Analysis of Algorithms

What's hot (18)

PDF
09. amortized analysis
PPT
Amortized analysis
PPT
Aoa amortized analysis
PPT
Amortized
PDF
13 Amortized Analysis
PPT
Amortized Analysis
RTF
Amortized complexity
PPTX
Adauctions
PDF
12 Greeddy Method
PDF
Nrtl activity coefficient for mixture1
PDF
Synchronous Loadable Up and Down Counter
PPT
Solving a “Transportation Planning” Problem through the Programming Language “C”
PPT
Amortized analysis
PDF
Hw5 2017-spring
PPTX
A star
PDF
Vb scripting
DOCX
Write a program to print out all armstrong numbers between 1 and 500
PPTX
Topic 1.2
09. amortized analysis
Amortized analysis
Aoa amortized analysis
Amortized
13 Amortized Analysis
Amortized Analysis
Amortized complexity
Adauctions
12 Greeddy Method
Nrtl activity coefficient for mixture1
Synchronous Loadable Up and Down Counter
Solving a “Transportation Planning” Problem through the Programming Language “C”
Amortized analysis
Hw5 2017-spring
A star
Vb scripting
Write a program to print out all armstrong numbers between 1 and 500
Topic 1.2
Ad

Viewers also liked (17)

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

Similar to Amortized complexity (20)

PPT
Lec-32 Recursion - Divide and Conquer in Queue
PPTX
DOC-20230417-WA0013.-7-27.pptx
PPTX
5.2 Least Squares Linear Regression.pptx
PDF
International Journal of Engineering Research and Development (IJERD)
DOCX
Basic Computer Engineering Unit II as per RGPV Syllabus
PDF
Cs6402 daa-2 marks set 1
PPT
Big-O notations, Algorithm and complexity analaysis
PPT
algo_vc_lecture8.ppt
PPT
Asymptotic Notation
PPT
Lec03 04-time complexity
PPT
Big Oh.ppt
PPTX
Asymptotic Analysis in Data Structure using C
PDF
economic load dispatch and unit commitment power_system_operation.pdf
PDF
WVKULAK13_submission_14
PPT
PPTX
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
PPTX
Unit i basic concepts of algorithms
PPTX
Dynamic programming1
PDF
Bellmon Ford Algorithm
PPTX
Ch-2 final exam documet compler design elements
Lec-32 Recursion - Divide and Conquer in Queue
DOC-20230417-WA0013.-7-27.pptx
5.2 Least Squares Linear Regression.pptx
International Journal of Engineering Research and Development (IJERD)
Basic Computer Engineering Unit II as per RGPV Syllabus
Cs6402 daa-2 marks set 1
Big-O notations, Algorithm and complexity analaysis
algo_vc_lecture8.ppt
Asymptotic Notation
Lec03 04-time complexity
Big Oh.ppt
Asymptotic Analysis in Data Structure using C
economic load dispatch and unit commitment power_system_operation.pdf
WVKULAK13_submission_14
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
Unit i basic concepts of algorithms
Dynamic programming1
Bellmon Ford Algorithm
Ch-2 final exam documet compler design elements

Recently uploaded (20)

PPTX
Current and future trends in Computer Vision.pptx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Artificial Intelligence
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
introduction to high performance computing
PPT
Occupational Health and Safety Management System
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Current and future trends in Computer Vision.pptx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Nature of X-rays, X- Ray Equipment, Fluoroscopy
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Safety Seminar civil to be ensured for safe working.
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
Visual Aids for Exploratory Data Analysis.pdf
Fundamentals of safety and accident prevention -final (1).pptx
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
UNIT 4 Total Quality Management .pptx
Artificial Intelligence
R24 SURVEYING LAB MANUAL for civil enggi
introduction to high performance computing
Occupational Health and Safety Management System
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...

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 .