SlideShare a Scribd company logo
1 of 4
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 white-paper
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 least significant bit. Following the update of the second
digit , the amount spent is 2d*2 in which 3d is spent to update two least significant digits and
the second least significant bit now has credit d . Proceeding in this way , we can sum up credit
on each digit of the display always equal (2d-d)v , where 2d be the amortized cost , d the actual
cost and v the value of the digit. So, we should use the potential function
P(n) = (2d-d)*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) = d(1-q*1) ;
So the amortized cost for the display change = actual cost + p(n) = (q+1)d +P(n) = (q+1)d + d(1-
2*1) = 2d .
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

Storage organization and stack allocation of space
Storage organization and stack allocation of spaceStorage organization and stack allocation of space
Storage organization and stack allocation of spaceMuhammad Haroon
 
Artificial Intelligence- TicTacToe game
Artificial Intelligence- TicTacToe gameArtificial Intelligence- TicTacToe game
Artificial Intelligence- TicTacToe gamemanika kumari
 
Informed and Uninformed search Strategies
Informed and Uninformed search StrategiesInformed and Uninformed search Strategies
Informed and Uninformed search StrategiesAmey Kerkar
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMRajendran
 
Elements of Dynamic Programming
Elements of Dynamic ProgrammingElements of Dynamic Programming
Elements of Dynamic ProgrammingVishwajeet Shabadi
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and SearchHitesh Mohapatra
 
CNIT 141: 9. Elliptic Curve Cryptosystems
CNIT 141: 9. Elliptic Curve CryptosystemsCNIT 141: 9. Elliptic Curve Cryptosystems
CNIT 141: 9. Elliptic Curve CryptosystemsSam Bowne
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generatorvinithapanneer
 

What's hot (20)

Storage organization and stack allocation of space
Storage organization and stack allocation of spaceStorage organization and stack allocation of space
Storage organization and stack allocation of space
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Artificial Intelligence- TicTacToe game
Artificial Intelligence- TicTacToe gameArtificial Intelligence- TicTacToe game
Artificial Intelligence- TicTacToe game
 
Post Machine
Post MachinePost Machine
Post Machine
 
Informed and Uninformed search Strategies
Informed and Uninformed search StrategiesInformed and Uninformed search Strategies
Informed and Uninformed search Strategies
 
Greedy method
Greedy method Greedy method
Greedy method
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
POST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEMPOST’s CORRESPONDENCE PROBLEM
POST’s CORRESPONDENCE PROBLEM
 
Elements of Dynamic Programming
Elements of Dynamic ProgrammingElements of Dynamic Programming
Elements of Dynamic Programming
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Loop optimization
Loop optimizationLoop optimization
Loop optimization
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and Search
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
Informed search
Informed searchInformed search
Informed search
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
CNIT 141: 9. Elliptic Curve Cryptosystems
CNIT 141: 9. Elliptic Curve CryptosystemsCNIT 141: 9. Elliptic Curve Cryptosystems
CNIT 141: 9. Elliptic Curve Cryptosystems
 
Adaptive Huffman Coding
Adaptive Huffman CodingAdaptive Huffman Coding
Adaptive Huffman Coding
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generator
 
tic-tac-toe: Game playing
 tic-tac-toe: Game playing tic-tac-toe: Game playing
tic-tac-toe: Game playing
 

Viewers also liked

Viewers also liked (8)

Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
TrifleGoogly
TrifleGooglyTrifleGoogly
TrifleGoogly
 
Wwf2012990
Wwf2012990Wwf2012990
Wwf2012990
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Junior Seminar 2013
Junior Seminar 2013Junior Seminar 2013
Junior Seminar 2013
 
Asset accounting
Asset accountingAsset accounting
Asset accounting
 
Outoftheboxdeck
OutoftheboxdeckOutoftheboxdeck
Outoftheboxdeck
 
Using Social Software to Make Blended Learning a Success
Using Social Software to Make Blended Learning a Success Using Social Software to Make Blended Learning a Success
Using Social Software to Make Blended Learning a Success
 

Similar to Amortized complexity

Amortized complexity
Amortized complexityAmortized complexity
Amortized complexityparamita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexityparamita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexityparamita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexityparamita30
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexityparamita30
 
Amortized Analysis of Algorithms
Amortized Analysis of Algorithms Amortized Analysis of Algorithms
Amortized Analysis of Algorithms sathish sak
 
DOC-20230417-WA0013.-7-27.pptx
DOC-20230417-WA0013.-7-27.pptxDOC-20230417-WA0013.-7-27.pptx
DOC-20230417-WA0013.-7-27.pptx03Shrishti
 
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.pptxMaiEllahham1
 
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 SyllabusNANDINI SHARMA
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Vai Jayanthi
 
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 CMeghaj Mallick
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Unit i basic concepts of algorithms
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithmssangeetha s
 
Aoa amortized analysis
Aoa amortized analysisAoa amortized analysis
Aoa amortized analysisSalabat Khan
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexityAbbas Ali
 

Similar to Amortized complexity (20)

Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized complexity
Amortized complexityAmortized complexity
Amortized complexity
 
Amortized Analysis of Algorithms
Amortized Analysis of Algorithms Amortized Analysis of Algorithms
Amortized Analysis of Algorithms
 
09. amortized analysis
09. amortized analysis09. amortized analysis
09. amortized analysis
 
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
 
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
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1
 
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
 
Bellmon Ford Algorithm
Bellmon Ford AlgorithmBellmon Ford Algorithm
Bellmon Ford Algorithm
 
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
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
Slide2
Slide2Slide2
Slide2
 
Aoa amortized analysis
Aoa amortized analysisAoa amortized analysis
Aoa amortized analysis
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 

Recently uploaded

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 

Recently uploaded (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 

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 white-paper 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 least significant bit. Following the update of the second digit , the amount spent is 2d*2 in which 3d is spent to update two least significant digits and the second least significant bit now has credit d . Proceeding in this way , we can sum up credit on each digit of the display always equal (2d-d)v , where 2d be the amortized cost , d the actual cost and v the value of the digit. So, we should use the potential function P(n) = (2d-d)*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) = d(1-q*1) ; So the amortized cost for the display change = actual cost + p(n) = (q+1)d +P(n) = (q+1)d + d(1- 2*1) = 2d .
  • 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 .