Chapter 1 Analysis
Summary: horizontal analysis is a tool used to analyze algorithms that execute a series of similar operations. It limits the actual cost of the entire operation sequence. This chapter introduces three methods of analysis, namely clustering analysis, accounting method, and potential energy method. Each method is analyzed by analyzing the stack operation and adding 1 to the binary counter. Finally, this chapter analyzes the cost limitation of dynamic table expansion and contraction using the method of table analysis.
1.Clustering Analysis
It is proved that the total time of the sequence consisting of n and N operations is T (n) in the worst case ). Therefore, the average cost of each operation is T (N)/n.
2.Accounting Method
Different operations are charged with different fees. The actual cost of some operations is more or less. The amortized cost of an operation can be viewed as the actual cost and deposit (or saved or used up ). Note that the total deposits in the data structure must always be non-negative.
For example, for Stack operations, pay 2 RMB for each push, 1 RMB for the actual cost of the push operation, and 1 RMB for the cost of the POP element. Pop operations are free of charge.
3.Potential Energy Method
The key to the potential energy method is to define the potential function. The potential function maps each data structure di into a real number PHI (DI), that is, the potential associated with the data structure di. Di is the result of the I operation that acts on the data structure Di-1. The potential function must be equal to or greater than or equal to diameter (D0 ).
The spread price of each operation is the actual cost plus the increase caused by this operation. The total amortized cost of N operations is an upper limit of the total actual cost.