Data Structure Basics

The data emphasize the importance of structure, it is between a core curriculum between mathematics, computer hardware and software three, Program = algorithm + data structure

1-1 data structure types:

A logical structure

1) linear structure
"linear" data structures: one linear relationship, such as the number of library management systems.
Special: queue and stack string.
Promotion: array, generalized list.

2) non-linear structure
"tree" data structure: level one to many relationship, such as a computer file system.
"FIG" data structure: a mesh-many relationship, such as a network and a network communication drawings FIG.
And wherein the tree comprises a binary tree, including FIGS directed and non-directed graph.
3) the collection structure.

Second, the storage structure

1) sequential storage structure: data storage from the low to higher addresses, the array type is described by C.
2) Storage Structure: Each node occupies two consecutive storage units, a storage node information, the other party stored first address of the subsequent node, C is described by pointer type.

1-2 Basic Concepts

Data : the symbol represents objective things, such as integers and real numbers, strings and the like.
Data elements : the basic unit of data, for a complete description of the object.
Data entry : Composition member data elements.
Data objects : the same properties of the data elements of the set

1-3 abstract data types and data type

1, the data type (Date Type) is set and a definition of a set of values ​​of operating in this general term value set.

2, abstract data types (the ADT), generally refers to a user-defined, represents a mathematical model and the defined application of a generic name a set of operations on the model, comprises: data objects, collections, and the relationship of the data objects the basic set of operations on data objects.
Defined format is as follows:
the ADT abstract data type name
{
<definition data object> data object
<defines data relationships> Data Relationship
Basic Operation <define the basic operation>
} the ADT abstract data type name
is defined format basic operations:
a basic operation (parameter table)
initial conditions: <described initial condition>
result: <described operation result>
two types of parameters basic operations:
assignment parameters: operating input values only
reference parameter: the "&" starts, and may provide input values return to the operating result.
It represents and implementation of abstract data types:
(1) type and predefined constants:

//函数结果状态代码
#define OK 1
#define ERROR 0
#define OVERFLOW -2
//Status 是函数返回值类型,其值是函数结果状态代码。
typedef int Status;

When the self-defined data element types as agreed ElemType, in using this type of data by a user; (2) data structure representation (storage structure) described a type definition (typederf).
(3) the basic operation algorithms are described by a function of the form:

函数类型 函数名(函数参数表)
{
	//算法说明
	语句序列
}//函数名
	

When the function returns the result status code value is a function, the function is defined as Status type.
(4) dynamic allocation and release of memory:
the use of new and delete dynamic allocation and release of memory space:
allocate space pointer variable = new data type
free space delete pointer variable
(5) assignment:
series assignment: variable name 1 = variable name 2 variable name = ... = n = expression.
Group assignment :( variable name 1, variable name ... n) = (Expression 1, ..., expression n)
in assignment: 1 structure name structure name = 2;
structure name = (value 1, value 2, ..., value n)
conditions of assignment: variable name = conditional expressions? Expressions T: F expression
exchange assignment: variable name 1 <-> 2 variable name

1-4 algorithm and algorithm analysis:

First, the definition of the algorithm: a finite sequence of operations to solve certain problems predetermined.

Second, the characteristics of the algorithms: finite, certainty, feasibility, input and output.

Third, the basic criteria for evaluating the merits of the algorithm: correctness, readability, robustness, efficiency.

four,

Time complexity of the algorithm:

1, the most important factor affecting the cost of the algorithm is a matter of time scale (algorithm how much input issue), generally denoted by n, n, the longer algorithm execution time.

2, statement execution time is approximately a = repeatedly executed and execution time product (analysis by unit time) of the desired number of times (frequency statement).

3, the time complexity of the algorithm definition:

1) For a simple algorithm: direct calculation of the frequency and all statements.

2) For complex algorithms: only statement (Repeat execution time is proportional to the number of algorithms and "basic statement", the running time of the algorithm contributed the most) of the number of executions to measure the workload of the algorithm.

Examples of a simple algorithm: Algorithm seeking product of two matrices:

for(i=1;i<n;i++)      //频度为 n+1 
 for(j=1;j<n;j++)     //频度为 n*(n+1)
 {   
  c[i][j]=0;          //频度为 n^2 
  for(k=1;k<=n;k++)   //频度为 n^2*(n+1) 
  c[i][j]=c[i][j]+a[i][k]*b[k][i];//频度为 n^3 
 } 

Wherein the sum of frequencies are all statements and function matrix of order n is expressed by F (n)
.
f (n) / n ^ 3 = C, i.e., f (n) and n is the cube of the same order, or same order of magnitude, the number of stages indicated by "O"

Time Algorithm measure of T (n) = O (f (n)), the execution time of the algorithm is the same as the growth rate of f (n) growth.

4, the time complexity of the analysis algorithm basic methods:
find the maximum frequency of that statement as a basis statement, the frequency of which is calculated to give the function of the problem size n f (n)

5, the time complexity of the non-recursive algorithm analysis example:
a) Constant order: T (n) = O (1)
2) linear order: T (n) = O ( n), the linear of the order: T (n) = O (n-* Iog2 (n-));
. 3) polynomial order:. T (n) = O (n ^ k)
as the square of the order: T (n) = O ( n ^ 2)
the cubic order: T (n) O = (n ^. 3)
. 4) of the order: T (n) = O (Iog2 (n))
. 5) exponential order: T (n) = (2 ^ n) O
in general, increase with n, T (n) algorithm for an optimal hello slow growth algorithm, obviously inefficient index order, try to choose the order of the polynomial algorithm.

When a number of cycles, the time complexity of the algorithm (n) is determined by the frequency f in the basis statement cycle deepest

Fifth, the space complexity of the algorithm:
1. Definition: Algorithm as a measure of the required storage space.
S (n) = O (f (n));
Note: In general, in view of the operational space is more adequate, the time complexity of the algorithm as the focus of the analysis.

Published 34 original articles · won praise 85 · views 4633

Guess you like

Origin blog.csdn.net/weixin_45895026/article/details/103825369