The storage structure of data in data structure


theme: channing-cyan

Keep creating and accelerate growth! This is the 27th day that I have participated in the "Nuggets Daily New Plan·October Update Challenge". Click to view event details

Data storage structure

The role of data storage structure

The storage structure of data should correctly reflect the logical relationship between data elements. That is to say, when designing a storage structure corresponding to a certain logical structure, two aspects of information need to be stored in the computer memory, that is, all data in the logical structure should be stored. The logical relationship between elements and stored data elements, so the storage structure of data is called the image of the logical structure .

21f71e14b626374a397e6309b07b6d0.jpg

In general, the storage structure is computer-oriented, and the basic goal is to store data and its logical relationships into the computer.

  • Code example```java class Student{ int NO; //Student number String names; //Name int score; //Score

    public Student(int NO1,String names1,int score1){ NO=NO1; names=names1; score=score1; } //Define an array to store the student's score table Student1 st=new Student1[2]; st[ 0] = new Student1(20221025,"ikun",100); st[1] = new Student1(20221026,"小黑子",0); st[2] = new Student1(20221027,"李智",60 ); }

``` Note: The characteristic of this storage structure is that all elements are stored in a storage unit with consecutive addresses. Logically adjacent elements are also adjacent in physical locations, so no additional space is needed to express the logic between elements. relation.

Type of storage structure

sequential storage structure

The sequential storage structure stores logically adjacent elements in physically adjacent storage units. The logical relationship between elements is reflected by the adjacency relationship of the storage units (direct mapping). We generally use arrays to implement this - Features : 1. Save storage space, because all storage units allocated to data are used to store element values, and the logical relationship between elements does not occupy additional storage space, just like the code example above. 2. Random access to nodes can be achieved, that is, each element corresponds to a serial number, and the storage address of the element can be directly calculated from this serial number (this is also the definition)

chain storage structure

Each logical element in the chain storage structure is stored with a node. Logically adjacent elements are not required to be adjacent in physical locations. The logical relationship between elements is represented by additional pointer fields. We generally use pointers to achieve this .

  • Advantages: Easy to insert and delete operations. Only the pointer field of the corresponding node needs to be modified, and the node does not need to be moved.
  • Disadvantages: Compared with the sequential storage structure, the space utilization is lower because a part of the storage unit needs to be allocated to store the logical relationship between elements. Because logically adjacent elements are not necessarily adjacent in the storage space , random access cannot be performed.

Index storage structure

The index storage structure usually stores element information and also creates additional index tables. Each item in the index table is called an index item, and the general form of an index item is a keyword, address, etc. The keyword uniquely identifies an element, the index table is ordered by the keyword, and the address serves as the pointer to it. This storage structure can greatly improve the speed of data query. It is similar to the table of contents in our book. According to the keywords and page numbers in the table of contents, you can quickly find the content you want to see. - The linear structure uses the index storage method to enable random access to elements. When performing insertion and deletion operations, only the storage address of the corresponding element stored in the index table needs to be moved. - Disadvantages: added index table, reduced space utilization

Hash storage structure

The basic idea of ​​the hash storage structure is to directly calculate a value through a hash function based on the key of the element, and use this value as the storage address of the element. It only stores element data and does not store the logical structure between elements. Usually suitable for situations where data can be quickly searched and inserted. - Advantages: The search speed is fast. As long as the keyword of the element to be searched is given, the storage address of the element can be immediately calculated (you can learn about the file storage of blockchain IPFS and so on).

Summarize

Such a variety of storage structures may exist separately in some simple practical applications. More complex practical applications generally use a combination of multiple storage structures. Mainly considering the convenience of operation implementation and the spatiotemporal performance requirements of the algorithm, the storage structure is determined according to the needs.

Guess you like

Origin blog.csdn.net/y943711797/article/details/132974240