I. Basic concepts and terminology
1. Data: A symbolic representation of the information. In computer science, it refers to all the symbols that can be entered into a computer and processed by a computer program.
2. Data Elemet: is the basic unit of data, which is usually considered and processed as a whole in computer programs.
A data element can consist of several data items. A data item is an indivisible minimum unit of data.
3. Data Object: A collection of data elements of the same nature. is a subset of the data.
4. Data Structure: A collection of data elements that have one or more specific relationships between each other. The form of the data structure is defined as: The data structure is a two-tuple: data-structure= (D, S)
Where: D is a finite set of data elements, and S is a finite set of relationships on D.
The interrelationships between data are called logical structures.
The logical structure of the data is a computer-independent description of the logical relationship between the data elements. From a collection point of view, they can be represented by a two-tuple b= (d, R), where D is a collection of data elements, and R is a collection of relationships on D.
According to the view of the collection, the logical structure of the data has two elements: one is the data element; the other is the relationship.
5. Generally divided into four basic structures:
Collections: Data elements in a structure have no other relationship than the same type.
Linear structure: There is a one-to-one relationship between data elements in the structure.
Tree structure: There is a one-to-many relationship between the data elements in the structure.
Graphic structure or mesh structure: There are many-to-many relationships between data elements in a structure.
6. The logical structure of data is divided into linear structures (relationships are linear) and non-linear structures (relationships are nonlinear) by relationship.
7. The physical structure of the data: refers to the logical structure of the data in the computer image, that is, the storage representation. Images include images of data elements and images of data relationships. The image of a data element is a node that represents a data element in a computer with a node (the node is the basic unit of the data structure discussion). There are two types of images for relationships, sequential and non-sequential images.
The data structure mainly refers to the logical structure and the physical structure.
8. Sequential storage structure and non-sequential storage structure :
The sequential storage structure is logically adjacent to the data element stored in the physical location adjacent to the storage unit, the relationship of the element is represented by the adjacency relationship of the storage unit.
A non-sequential storage structure is a data element that can be stored anywhere within a computer (it requires logically adjacent elements to be adjacent to the physical location), and their logical relationships are linked by pointers. Therefore, the non-sequential storage structure is also called the chain storage structure. The chained storage structure divides the storage units of data elements into two parts, each of which holds data and pointers, called data fields and pointer fields.
9. Algorithm : A description of the solution steps for a particular problem. An algorithm is a finite sequence of instructions, where each instruction represents one or more operations.
10. The algorithm has the following five properties :
Poor : An algorithm must always end after the execution of a poor step, and each step is completed in a poor period of time.
certainty : Every instruction in an algorithm must have a definite meaning. There is no ambiguity. And the algorithm has only one entry and one exit.
feasibility : An algorithm is feasible. That is, the operation described by the algorithm can be implemented by the implementation of the basic algorithm for a finite number of times.
input : An algorithm has 0 or more inputs, which are taken from a particular collection of objects.
output : An algorithm has one or more outputs that are the amount of certain relationships with the input.
11. Algorithm Evaluation Criteria
Correctness: Reasonable data input, in the limited operating time to obtain the correct results.
Robustness: The ability to respond to and manipulate unreasonable data inputs.
Readability: A convenient level for people to read.
Simplicity: The simplicity of using data structures and methods.
Time complexity (computational complexity): The relative measure of the algorithm's elapsed time.
Spatial complexity: a measure of the amount of space that is temporarily occupied in the algorithm's operation.
12. Time Complexity (Tine complexity): If there are two normal numbers C and n0, for all n>=n0, there is |f (n) |<=c|g (n) | , it is recorded as f (n) =o (g (n))
Frequency: Refers to the number of times that the statement has been repeatedly executed
worst-case complexity of time
There are several possible considerations when parsing an algorithm:
-
- The minimum number of basic operations required for the algorithm to complete the work, i.e. the optimal time complexity
- The maximum number of basic operations required for the algorithm to complete the work, i.e. the worst time complexity
- How much basic operation is required for the algorithm to complete the work, i.e. average time complexity
For the optimal time complexity, its value is small, because it does not provide any useful information, it reflects only the most optimistic and ideal situation, no reference value.
For the worst time complexity, it provides a guarantee that the algorithm will be able to complete the work in this kind of basic operation.
For the average time complexity, is a comprehensive evaluation of the algorithm, so it is a complete and comprehensive reflection of the nature of the algorithm. On the other hand, this measure does not guarantee that not every calculation can be done within this basic operation. Moreover, for the calculation of the average condition, it is difficult to calculate because the instance distribution of the applied algorithm may be uneven.
Therefore, we focus on the worst case scenario of the algorithm, i.e. the worst time complexity.
several basic calculation rules of time complexity
-
- The basic operation, that is, only the constant term, that its time complexity is O (1)
- Sequential structure, time complexity calculated by addition
- Cyclic structure, time complexity calculated by multiplication
- Branching structure, maximum time complexity
- When judging the efficiency of an algorithm, it is often only necessary to pay attention to the highest number of operations, other minor items and constant items can be ignored
- In the absence of special instructions, the time complexity of the algorithm we are analyzing refers to the worst time complexity
Common time Complexity
example of execution count function |
Order |
Informal terminology |
12 |
O (1) |
Constant order |
2n+3 |
O (N) |
Linear order |
3n2+2n+1 |
O (N2) |
Square Order |
5log2n+20 |
O (LOGN) |
Logarithmic order |
2n+3nlog2n+19 |
O (NLOGN) |
Nlogn Order |
6n3+2n2+3n+4 |
O (N3) |
Cubic order |
2n |
O (2n) |
Exponential order
|
13. Spatial complexity (space complexity): The measurement of the storage space required by the algorithm is recorded as: S (n) =o (f (n)) where n is the size (or size) of the problem
The space occupied by the algorithm is occupied by the algorithm itself, the input and output data occupy and the temporary occupation in running.
The same problem, the algorithm is different, the running of the temporary space is different, that is, the spatial complexity of different.
Only the amount of storage space allocated for local variables in the run is considered, and is generally expressed in order of magnitude.
---restore content ends---
01. Data Structures and algorithms