DS Chapter 2: ADT Representation and Implementation, Algorithm and Algorithm Analysis

1. Representation and realization of abstract data types

Abstract data type independent of the specific implementation , the data and operations packaged together.
ADT is equivalent to describing the problem at the conceptual level (abstraction level) .
Class is equivalent to describing the problem at the implementation level .

Two, algorithm and algorithm analysis

Algorithm definition: It is a finite sequence of operations prescribed to solve a certain type of problem.

1. Five characteristics

(1)有穷性。

An algorithm must always end after executing finite steps, and each step must be completed in finite time.

(2)确定性。

For the operations that should be performed in each case, there are exact rules in the algorithm, and there will be no ambiguity, so that the executor or reader of the algorithm can clarify its meaning and how to perform it.

(3)可行性。

All operations in the algorithm can be implemented by performing a limited number of basic operations that have been implemented.

(4)输入。

An algorithm has zero or more inputs. When describing an algorithm with a function, the input is often represented by formal parameters, and when they are called, the input value is obtained from the calling function.

(5)输出。

An algorithm has one or more outputs, which are the results of information processing by the algorithm. An algorithm without output has no meaning. When describing an algorithm with a function, the output is often represented by a return value or a formal parameter of a reference type.

2. Four evaluation criteria

(1)正确性。

With reasonable data input, correct results can be obtained within a limited running time.

(2)可读性。
(3)健壮性。

When the input data is illegal, a good algorithm can properly react or process accordingly without
producing some inexplicable output results.

(4)高效性。

Efficiency includes two aspects: time and space.


3. Time Complexity (Time Complexity)

Which factors are related to:

Environmental factors such as software and hardware The most important factor is the scale of the problem other factors
Machine speed, compiler quality The sum of the execution time of the statement Query an element in the array, whether the element exists, and where it exists

问题规模: It is the amount of input for the algorithm to solve the problem, which is the essential representation of the problem size, generally represented by an integer n.

语句频度 : The number of repeated executions of a statement

With the number of executions in proportion to the "basic statement" execution time of the algorithm is 语句频度to measure the algorithm workload .

That is the problem when a sufficiently large scale to 语句频度indicate the algorithm workload way to calculate the complexity of the time
(I do not know, say there is no clear ah, anyway, I got it ...)


The time complexity definition is given in the book :

In general, the number of repeated executions of the basic sentence in the algorithm is a certain function f0(n) of the problem size n , and the time measurement of the algorithm is recorded as T(n) = O(f(n)), which
means that with the increase of the problem size n Large, the growth rate of the algorithm execution time is the same as f(n), which is called the progressive time complexity of the algorithm , or time complexity for short .
·
Where O (Order of Magnitude of magnitude) , represents the upper limit of the growth rate.

Therefore, algorithm analysis does not accurately count the time required to actually execute the algorithm.
It can:

  • Ignore low power terms
  • Ignore high power coefficients
  • At the same time, it can be expressed by a recursive equation

And for space complexity S(n) = O(f(n))

  • Just analyze the algorithm in the realization of the auxiliary space required on it

Time complexity and space complexity often affect each other .
When a better time complexity is pursued, it
may occupy more storage space. ( 用“空间换时间”) It
may make the performance of space complexity worse, and vice versa. Of course.

Under normal circumstances, in view of the relatively sufficient computing space ,
people use the time complexity of the algorithm as an index of the pros and cons of the algorithm.


End of this article

Guess you like

Origin blog.csdn.net/m0_46156900/article/details/114302374