"Algorithm + Data Structure = Program"
——Worth (father of Pascal language, pioneer of structured programming, famous Swiss scientist)
1. The concept of data structure
Data structure is the reflection of data in the real world and the relationship between them. It can be described from two levels: logical structure and storage (physical) structure .
2. Logical structure
The logical structure of data refers to the logical relationship between various data elements, which is the organizational form of data elements that can be perceived by users.
1. Assemble
The relationship between data elements in a collection is "loose" .
2. Linear structure
There is a "one-to-one" relationship between data elements in a linear structure .
3. Tree structure
There is a "one-to-many" relationship between data elements in the tree structure .
4. Graphic structure
There is a "many-to-many" relationship between data elements in the graph structure .
Sometimes, logical structures are also divided into two categories, one is linear structures and the other is non-linear structures - sets, trees, graphs.
3. Storage (Physical) Structure
The storage (physical) structure of data is the realization of the logical structure of data in the computer.
1. Sequential storage method
The sequential storage method refers to storing all data elements in a continuous storage space, and making the corresponding physical positions of logically adjacent data elements also adjacent, that is, the logical positional relationship of the data elements is consistent with the physical positional relationship .
2. Chain storage method
Chained storage technology stores data elements in any physical location. The storage representation corresponding to each data element consists of two parts, one part can store the data element value itself, and the other part is used to store pointers representing logical relationships, namely Relationships between data elements are indicated by additional pointers.
3. Index storage method
The index storage method adds an index table while storing data elements. Each item in the index table includes a keyword and an address, wherein the keyword is a data item that can uniquely identify a data element, and the address indicates the storage address of the data element or the first address of the storage area.
4. Hash (hash) storage method
The hash (hash) storage method is to store data elements in a continuous area. The specific storage address of each data element is the key value of the data element, which is directly calculated by the hash (hash) function. .
Among the above 4 storage methods, sequential storage and chain storage are the two most basic and commonly used storage methods; index storage and hash storage are two storage methods that are often used to improve search efficiency.
4. Data operation
The operation of data is to process the data in some way, also known as data operation.
Commonly used operations can be summarized as follows:
1. Create operation : create a data storage structure.
2. Destroy operation : release all the space of the existing storage structure.
3. Insert operation : Add a specified new data element at the appropriate position of the data storage structure.
4. Delete operation : delete a data element in the data storage structure that meets the specified condition.
5. Search operation : Find data elements that meet the specified conditions in the data storage structure.
6. Modify operation : modify the value of a data element in the data storage structure.
7. Traverse operation : visit each data element in the data storage structure according to a certain path and only visit once.