**program = algorithm + data structure**
N. Professor Niklaus Wirth proposed:

program = algorithm + data structure

The above formula illustrates the following two questions:

(1) The algorithm determines how data is structured and organized (algorithm → data structure).

(2) The choice of the algorithm depends on the data structure (data structure → algorithm) as the basis.

Software = program + documentation (software engineering perspective) **solving problems of non-numerical calculation**

The main consideration is to design the appropriate data structure and the corresponding algorithm.

That is, the first thing to consider is how to represent, organize, and store all the relevant information.

Therefore, it can be considered that the data structure is a subject of the computer operation object and the relation and operation between them in the programming problem of non-numerical computation. **Basic concepts of data structure**

Several concepts:

**data:** a symbolic representation of an objective thing. In computer science, the name of all the symbols that can be entered into a computer and processed by a computer program.

**data element:** is the basic unit of data, which is usually considered and processed as a whole in computer programs.

A data item is an indivisible minimum unit of data. A data element can consist of several data items.

**data object:** is a collection of data elements of the same nature. is a subset of the data.

What is a data structure.

Define the

is a collection of data elements that have one or more specific relationships between each other.

Define 2--

A group of data organized in a logical relationship (or a collection of data elements that are called structures) applies computer language and stores them in the memory of the computer in a certain way, and defines a set of operations on it. **Logical Structure**

Abstract relationships between data elements (referred to as logical structures).

Regardless of the storage of the data, independent of the computer, it is a mathematical model abstracted from specific problems.

Storage structure (physical structure)--

The data elements and their relationships (the logical structure of the data) are stored in the computer's memory.

is the realization of logical structure with computer language, which relies on computer language.

Operations (algorithms)

Logical Structure-partitioning method one

(1) Linear structure--

There is only one start and one terminal node, and all nodes have at most one direct forward and one successor.

Example: Linear table, Stack, queue, string

(2) Nonlinear structure--

A node may have multiple direct precursors and direct successors.

For example: trees, graphs, etc.

Logical Structure-partitioning method two

The data elements in a collection structure have no other relationship than one type.

There is a one-to-one relationship between data elements in a linear structure structure.

There is a one-to-many relationship between the data elements in the tree structure.

There are many-to-many relationships between data elements in a graph structure or a mesh structure. **Storage Structure**

Storage structure Two aspects of the content:

(1) Representation of the data element's own value (data field)

(2) Representation of the relationship between the node and other nodes (chain field)

Two basic storage methods:

(1) Sequential storage method (sequential storage structure)

(2) Link storage method (chained storage structure)

The same logical structure can adopt different storage methods (one or combination of the above), which mainly consider the convenience of computation and the space-time requirement of the algorithm. **computation of data structures (manipulation of the figures)**

⑴ Establish (create) a data structure;

⑵ Elimination (Destroy) a data structure;

⑶ Delete (delete) a data element from a data structure;

⑷ inserts a data element into a data structure;

⑸ access to a data structure (access);

⑹ modification of a data structure (the elements in) (Modify)

⑺ to sort a data structure (sort);

⑻ a data structure to search (search). **data types and abstract data types**

Data type: In a programming language, the type of data that a variable has.

Example 1, in Fortran language, the data types of variables are integer, real, and plural

Example 2, in C language

Data type: base type and construction type

Basic types: integer, float, character

Constructed type: array, struct, union, pointer, enum, custom

Note: The data structure is different from the datatype and also differs from the data object, which not only describes the data type of the data object, but also describes the interrelationships between the elements of the data object.

Abstract data type, or ADT: refers to a mathematical model and a set of operations defined on the model.

ADT is defined only as a set of logical attribute descriptions, independent of its representation and implementation within the computer. Therefore, no matter how the internal structure of ADT changes, as long as its mathematical characteristics are not changed, it does not affect its external use.

The formal definition of ADT is ternary: adt= (d,s,p)

Where: D is the data object, S is the set of relationships on D, and P is the basic set of operations on D.

The generally defined form of ADT is:

ADT < abstract data type name >{

Data objects: < definition of Data Objects >

Data relationship: Definition of < data relationship >

Basic operations: < definition of basic operations >

} ADT < abstract data type name >

The definition of data object and data relation is described by pseudo code.

The basic operation is defined as:

< basic operation name > (< parameter table >)

Initial conditions: < initial condition Description >

Operation Result: < operation result description >

Initial conditions: Describes the condition that the data structure and parameters should meet before the operation executes, and if not, the operation fails and the corresponding error message is returned.

Operating results: Describes the changes in the data structure and the results that should be returned when the operation is completed normally. **algorithm**

The concept and description of the algorithm:

What is an algorithm.

The so-called algorithm (algorithm) is a description of the solution method (step) for a particular problem.

A poor sequence consisting of several instructions for solving a particular problem.

A method for solving problems of computer program implementation

The concept and description of the algorithm:

An algorithm must meet the following five guidelines:

(1) Be poor-must be terminated after a limited instruction has been executed.

(2) certainty (no ambiguity)-

Each step of the algorithm must have a precise definition and no ambiguity.

(3) can (CAN) line sex-

Each step of the algorithm must be feasible, that is, each operation can be completed in a limited time.

(4) Input data-

An algorithm has an input of n (n>=0) initial data.

(5) Output data-

An algorithm has one or more output of valid information that has a certain relationship with the input.

The time complexity of common functions is increased by the number of increments and growth rate.

Constant order O (1)

Logarithmic order O (log2n)

Linear order O (n)

Linear logarithmic order O (nlog2n)

Square Order O (N2)

Cubic Order O (N3)

......

K Order O (NK)

Exponential order O (2n) **spatial complexity (space complexity)**

: Refers to the measure of the amount of storage space required when the algorithm is programmed to run in the computer. notation: S (n) =o (f (n))

Where: n is the size (or size) of the problem

This storage space typically includes three aspects: the storage space occupied by the

instruction constant variable;

The storage space occupied by the input data;

Secondary (storage) space.

in general, the spatial complexity of the algorithm refers to the secondary space.

One-dimensional array a[n]: Spatial complexity O (n)

Two-dimensional array a[n][m]: Spatial complexity O (n*m)