Data structure and algorithm - what is a linear table (linear storage structure)

We know that the best way to store data with a "one-to-one" logical relationship is to use a linear table. So, what is a linear table?

Linear table, the full name is linear storage structure . The way to store data using a linear table can be understood in this way, that is, "string all the data with a line and store them in physical space".

"One-to-one" logical relationship data
Figure 1 Data of "one-to-one" logical relationship


As shown in Figure 1, this is a set of data with a "one-to-one" relationship, and we then use a linear table to store it in physical space.

First, use "a thread" to "string" them in sequence, as shown in Figure 2:

Figure 2 "Linear" structure of data

In Figure 2, the left side is the "string" data, and the right side is the free physical space. To place this "string" of data in physical space, we can choose the following two methods, as shown in Figure 3.

Two Linear Storage Structures
Figure 3 Two linear storage structures

Figure 3a) is the storage method that most people think of, while Figure 3b) is rarely thought of. We know that the success of data storage depends on whether the data can be completely restored to its original form. If you pull up one end of the line in Figure 3a) and Figure 3b), you will find that the position of the data has not changed (same as Figure 1). Therefore, it can be concluded that both storage methods are correct.

The data with a "one-to-one" relationship is stored "linearly" in the physical space, and this storage structure is called a linear storage structure (referred to as a linear table) .

The data stored in the linear table requires the same data type as the data stored in the array, that is to say, the data stored in the linear table is either all integers or all strings. A set of data whose half is an integer and the other half is a string cannot be stored in a linear table.

Sequential storage structure and chained storage structure

From Figure 3, we can see that linear table storage data can be subdivided into the following two types:

  1. As shown in Figure 3a), the data is stored sequentially in a continuous block of physical space. This storage structure is called a sequential storage structure (sequence table for short);
  2. As shown in Figure 3b), the data is stored scattered in the physical space, and the logical relationship between them is saved through a line. This storage structure is called a chained storage structure (referred to as a linked list);

That is to say, the linear table storage structure can be subdivided into a sequential storage structure and a linked storage structure.

predecessor and successor

In data structures , each individual in a set of data is called a " data element " (or " element " for short). For example, Figure 1 shows the set of data, where 1, 2, 3, 4, and 5 are all elements in the set.

In addition, for data with a "one-to-one" logical relationship, we have been using unprofessional words such as "the left side (front) or right side (back) of an element". In fact, there are more accurate terms in the linear table :

  • The left adjacent element of an element is called " direct predecessor ", and all elements located on the left side of this element are collectively called " predecessor elements ";
  • The right adjacent element of an element is called " immediate successor ", and all elements to the right of this element are collectively called " successor elements ";

Taking element 3 in the data in Figure 1 as an example, its immediate predecessor is 2, and there are 2 precursor elements of this element, namely 1 and 2; similarly, the direct successor of this element is 4, and there are 2 successor elements, 4 and 5 respectively. As shown in Figure 4:

Guess you like

Origin blog.csdn.net/Itmastergo/article/details/131716071