Description: This post is used as a personal learning note. Reference material: [Data structure (C language version)]. Min
First, what is the data structure
Ii. Basic Concepts and terminology
Representation and implementation of abstract data types
Iv. Algorithm and algorithm analysis
First, what is the data structure
1) Solving practical problems with computers
General steps to solve a problem with a computer:
1. Abstraction from specific issues into a data model--"2. Design algorithm to solve this model--" 3. Finally, program-test-adjust to get the final answer
However, there are many more problems that are not numerically calculated and cannot be described by mathematical equations:
such as: library Automatic Retrieval system, man-machine chess problem, multi-x intersection, traffic lights management problems.
In simple terms, the data structure is a subject that studies the programming problem of non-numerical computation, the object of computer operation and the relation and operation between them.
The importance of data structures:
In computer science, data structures are not only the basis of general program design, but also the basis for designing and implementing compiler programs, operating systems, database systems, and other system program applications.
Ii. Basic Concepts and terminology
Data:
A generic term for symbols that can be entered into a computer and processed by a computer program.
Data element:
The basic unit of data. Generally considered and handled as a whole in a computer. Sometimes a data element contains multiple items of data, such as a book's bibliographic information as a data element, and the author and title of the bibliographic information is a data item.
Data object:
is a collection of data elements of the same nature and is a subset of the data. (Columns such as: A table in a database is a data object.) An integer set, an alphabetic set is also a data object)
Data structure (data structure):
A collection of data elements that are one or more specific relationships between each other.
The relationship between data elements is called a structure.
Depending on the relationship between the data elements, the following four structures are divided:
1. Collection: There is no relationship other than a collection
2. Linear structure: There is a one-to-one relationship between data elements
3. Tree structure: There is a one-to-many relationship between data elements
4. Mesh or graph structure: many-to-many relationships exist between data elements
The form of the data structure is defined as: The data structure is a two-tuple
Data_structure= (D, S)
D is a finite set of data elements, and S is a finite set of relationships above D.
Logical structure of the data:
The purpose of the discussion data structure is to implement it in the calculation, so it is also necessary to study how to represent it in the computer.
The representation of a data structure in a computer (also known as an image) is called a physical structure, also known as a storage structure. It includes representations of data elements and representations of relationships.
The smallest unit of information represented in a computer is a binary number, called a bit.
In a computer, we can use multiple bits to form a bit string to represent a data element, usually called the element or node.
When a data element consists of several data items, the sub-string corresponding to each data item in the bit string is called: Data field. So an element or node can be seen as an image of a data element in a computer.
Relationships between data elements:
1. Sequential images
Feature: The logical relationship between data elements is represented by the relative position of the data element in memory .
2. Non-sequential images
Feature: A pointer to the storage address of an element (pointer) represents the logical relationship between data elements.
The logical structure of the data and the storage structure are closely related, the design of any one algorithm depends on the selected data structure (logical structure), and the implementation of the algorithm depends on the adopted storage structure.
Data type: A concept that is closely related to data structures and is first seen in high-level programming languages to characterize the operations of objects.
A data type is a collection of values and a generic term that defines a set of operations that are set on this value.
Abstract data type (ADT): Refers to a mathematical model and a set of operations defined on the model. The definition of an abstract data type depends only on its set of logical characteristics, and how it is represented in the computer is not related to the implementation, that is, no matter how the internal mechanism changes, as long as its mathematical characteristics are not changed, it does not affect its external use.
For example, " integer " is an abstract data type, although implemented differently on different processors, it is the same for the user.
A software module with an abstract data type typically contains 3 parts that define, represent, and implement.
The definition of an abstract data type: Consists of a set of operations on a range and a range of values that can be subdivided into 3 types by its value:
1. Atomic type: Values are non-decomposed, columns such as integers
2. Fixed polymerization type: consisting of certain number of components, such as plural,
3. Variable aggregation type: The number of values is indeterminate, such as an ordered integer sequence
The latter two types are called struct types.
Corresponds to the form of the data structure, and the abstract type is represented by a ternary group:
(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, which defines abstract data types in the following format
ADT abstract data type name {
Data objects: Definition of Data Objects
Data relations: The definition of data relations
Basic operation: definition of basic operation
}ADT abstract data type name
The format definition for the basic operation:
The base operation name (parameter list) assignment parameter only provides input values. The reference parameter starts with &, and you can provide input values and return the result of the operation.
Initial conditions:< Initial condition Description > Describes the criteria that the data structure and parameters should meet before operation execution
Operation result:< operation result description >
Representation and implementation of abstract data types
Abstract data types can be represented and implemented by intrinsic types that use the data types already in the processor to illustrate the new structure and combine the new operations with the implemented operations.
Iv. Algorithm and algorithm analysis
Algorithm (algorithm):
is a description of the solution step for a particular problem, which is a finite sequence of instructions, where each instruction represents one or more operations, and an algorithm has 5 features:
1. Have poor 2 certainty 3, feasibility 4, input 5, output
Requirements for algorithmic design:
1. Correctness 2. Readability 3. Robustness 4. Efficiency and storage requirements
Measurement of algorithmic efficiency:
There are usually two methods for measuring the execution time of a program:
1. Post-mortem statistical methods
2. Methods of pre-analysis and estimation
An algorithm is composed of the control structure and the original operation, then the time of the algorithm depends on the combined effect of both.
The number of times the original operation was executed as the algorithm's time measurement:
In general, the number of basic operations performed in the algorithm is a function f (n) of the problem size n, which is the time measurement of the algorithm:
T (n) =o (f (n))
It indicates that the age problem scale n is increasing, the algorithm execution time growth rate and f (n) growth rate is the same, called the algorithm progressive time complexity, referred to as time complexity
General time complexity with constant order O (1), Linear order O (n), square order O (n squared) logarithmic order O (log n), exponent order O (2 N-squared)
Note: Sometimes, the time complexity of the algorithm is related to the input data, such as: bubble sort.
Storage space requirements for the algorithm:
Similar to the time complexity, where space complexity is used as a measure of the storage space required by the algorithm:
Note: S (n) = O (f (n))
Data Structure-Introduction