Logical and physical structure of data structures

insert image description here
The array in the figure is wrong.
An array is a specific way of storing data. It can be used to implement a linear table, but not only to represent a linear table, but also to represent a tree or a graph.
Arrays are stored in a contiguous memory that can be accessed randomly.
The implementation of a linear table with an array is called a sequence table, and the implementation of a linked list has no special name.
Trees are implemented with arrays and have no special name when they are implemented with linked lists.

1. Logical structure:

The logical structure is divided into four types: set structure, linear structure, tree structure, graph structure.

1.1 The so-called collection structure:

On the surface, there is no profound meaning, that is, the data elements belong to the same set, and there is no relationship between individual data elements. As shown below.

1.2 Linear structure:

Similar to a linear relationship, that is, there is a one-to-one relationship between data elements in a linear structure. Note: The focus is on one-to-one. As shown below.

1.3 Tree structure:

There is a one-to-many relationship between data elements in the tree structure. (The graph formed by each element and element relationship is similar to a tree diagram). Note: The relationship is one-to-many. As shown below.

1.4 Graphic structure:

There is a many-to-many relationship between data elements. As shown below.

To sum up the above points: Pay attention when using schematic diagrams to represent the logical relationship of data structures:

1. Treat each element as a node, represented by a circle.

2. The relationship between each element is represented by a connection line between nodes, and if the relationship has a direction, it is represented by a connection line with an arrow.

2. Physical structure (storage structure):

The physical structure is also called the storage structure, which is divided into four types, sequential storage structure, chain storage structure, index structure, and hash structure.

2.1 Sequential storage structure:

A contiguous memory space.
Pros: random access

Disadvantages: low insertion and deletion efficiency, fixed size

2.2 Chain storage structure:

Discontinuous memory space
Advantages: dynamic expansion of size, high insertion and deletion efficiency

Disadvantage: No random access.

2.3 Index storage structure:

In order to facilitate the search, the whole is unordered, but the index blocks are ordered, and additional space is required to store the index table. In addition to storing data elements in a set of memory spaces with continuous addresses, an index table needs to be established. The index in the index table indicates the storage location (subscript) of the storage node or the endpoint of the storage interval (subscript).

Advantages: An improvement to sequential search, high search efficiency

Disadvantage: additional space is required to store the index

2.4 Hash storage structure:

Select a function, the data element may store multiple data elements in the same location according to the function calculation storage location, causing address conflict

Advantages: The search can be found based on the data itself, with high search efficiency and high access efficiency.

Disadvantages: only random access by keyword, no sequential access, and no half access. Random access, not easy to search in sequence.

Guess you like

Origin blog.csdn.net/weixin_44313315/article/details/107164872