Home  >  Article  >  Sequential storage structure of linear table

Sequential storage structure of linear table

(*-*)浩
(*-*)浩Original
2019-06-04 09:25:3617537browse

Linear table is the most basic, simplest, and most commonly used data structure. A linear list is a type of data structure. A linear list is a finite sequence of n data elements with the same characteristics.

Sequential storage structure of linear table

#Linear tables are mainly represented by sequential representation or chain representation. In practical applications, they are often used in special forms such as stacks, queues, and strings.

Sequential representation refers to using a set of storage units with consecutive addresses to sequentially store the data elements of a linear table, which is called the sequential storage structure or sequential mapping of a linear table. It uses "physical location adjacency" to represent the logical relationship between data elements in the linear table, and can randomly access any element in the table.

The resulting storage structure is a sequential storage structure. Usually the sequential storage structure is described with the help of an array in a computer programming language (such as c/c).

The main advantage of the sequential storage structure is to save storage space, because the storage units allocated to data are all used to store node data (regardless of the need to specify the size of the array in the C/C language), The logical relationships between nodes do not occupy additional storage space. When this method is adopted, random access to nodes can be achieved, that is, each node corresponds to a serial number, and the storage address of the node can be directly calculated from this serial number. However, the main disadvantage of the sequential storage method is that it is inconvenient to modify. When inserting and deleting nodes, a series of nodes may need to be moved.

Recommended course: C Language Tutorial.

Structure code of linear table sequential storage structure:

#define MAXSIZE 20    
typedef int ElemType;
typedef struct
{
    ElemType data[MAXSIZE];
    int length;    // 线性表当前长度
} SqList;

Sequential storage structure encapsulation requires three attributes:

Storage The starting position of the space, the storage location of the array data, is the storage location of the linear table storage space.

The maximum storage capacity of the linear table: the length of the array MaxSize.

The current length of the linear table: length.

Note: The length of the array and the current length of the linear table need to be distinguished: the length of the array is the total length of the storage space for storing the linear table, and generally does not change after initialization. The current length of the linear table is the number of elements in the linear table, which will change.

Advantages and Disadvantages of Linear Table Sequential Storage Structure

The sequential storage structure of linear table, when storing and reading data, no matter where it is, the time complexity is O(1). When inserting or deleting, the time complexity is O(n).

This means that it is more suitable for applications where the number of elements is relatively stable, elements are not frequently inserted and deleted, and more operations are used to access data.

Advantages:

No need to add additional storage space to express the logical relationship between elements in the table.

You can quickly access elements anywhere in the table.

Disadvantages:

Insertion and deletion operations require moving a large number of elements.

When the length of the linear table changes greatly, it is difficult to determine the capacity of the storage space.

It is easy to cause "fragmentation" of storage space.

The above is the detailed content of Sequential storage structure of linear table. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn