Algorithm (4th Edition) -1.4.3 mathematical model

Source: Internet
Author: User

Summary: This section describes the concepts of approximate operation time, growth magnitude and cost model, and the method of algorithm Analysis.

Focus:

1. The basic insight of Knuth is simple-the total time a program runs is mainly about two points:

· Time-consuming execution of each statement;

· The frequency at which each statement is Executed.

The former depends on the computer, the Java compiler, and the operating system, which depends on the program itself and Input.

If we are aware of these properties for all parts of the program, you can multiply them and add the cost of all the instructions in the program to the total elapsed time.

If I do not understand the error, we mainly study the frequency of executing each statement.

2. We often use the approximate equals sign (~) to ignore smaller items, which greatly simplifies the mathematical formulas we deal with.

This notation allows us to use approximate methods to ignore items that are very complex but are low in power and do not contribute to the final Result.

For example:

N (N-1) (N-2)/6 = N^3/6-N^2/2+N/3 ~ N^3/6

3. definition:

· We use ~f (n) to represent all functions that are approaching 1 as the result of the increase in n, except for the F (n).

· We use G (n) ~ F (n) to denote G (n)/f (n) approaching 1 with the increase of N.

4. Generally the approximate method we use is G (n) ~ af (n), where f (n) = N^b (logn) ^c, where a, b, and C are constants. We will call F (n) the growth order of G (n).

5. We assume that the execution time required for each Java code block corresponds to the machine instruction is Fixed.

6. The most frequently executed instructions determine the total time of execution of the Program-we refer to these instructions as internal loops of the Program. The run time of many programs depends only on a small subset of the Instructions.

Understand the key to approximate running time!

7. The increase in threesum uptime is n^3, which is not related to whether it is implemented by Java or it runs on your laptop/on someone's phone/on a super-computer.

The main factor that determines this is that it needs to check all possible combinations of any three integers in the Input.

The algorithm you use (and sometimes the input model) determines the order of magnitude of growth.

Separating the algorithm from the specific implementation on a computer is a powerful concept because it is our knowledge of algorithmic performance that can be applied to any computer.

8. We used a cost model to evaluate the nature of the Algorithm.

This model defines the basic operations in the algorithm we are studying.

For example, the cost model for 3-sum problems is the number of times we access array Elements.

The role of the cost model: to translate the abstract cycle times into specific operation times, simulate the actual cost of the algorithm, and evaluate the Program's running Time.

9. For most programs, the steps required to get a mathematical model of its run time are as Follows:

· Determine the input model (function)and define the size of the problem (N);

· Identify inner loops;

· The cost model is determined according to the operation in the inner loop;

· For a given input, determine how often these operations are performed (the mathematical formula for N).

10.

· Table 1.4.5 common functions in algorithm analysis

· Table 1.4.6 Approximate functions commonly used in the analysis of algorithms

Do not seek mastery, but seek understanding.

Algorithm (4th Edition) -1.4.3 mathematical model

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.