Introduction to algorithms-Chapter 2-Analysis

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.