Comparison of sequential storage structure and chained storage structure

Source: Internet
Author: User

One: The sequential table is characterized by logically adjacent data elements, the physical storage location is also adjacent , and the storage space of the sequential table needs to be pre-allocated .

The advantages of this are:

(1) Simple method, all kinds of high-level languages have arrays, easy to implement.

(2) Do not add additional storage overhead to represent the logical relationship between nodes.

(3) The sequential table has the characteristics of random access by element ordinal.

Disadvantages:

(1) when inserting and deleting operations in the sequential table, the average half of the elements in the table are moved , so the efficiency of the N larger sequential table is low.

(2) The need to pre-allocate large enough storage space, the estimate is too large, it may lead to a large number of empty order table, pre-allocated too small, but also cause overflow.

Second, logically adjacent data elements in the linked list, the physical storage location is not necessarily adjacent, it uses pointers (references) to implement the logical relationship between elements. Also, the storage space of the linked list is dynamically allocated .

The most important features of the linked list are:

Easy to insert and delete operations.

Disadvantages:

(1) The storage density is reduced to occupy additional storage space between the elements. Storage density refers to the ratio of the storage units occupied by the data elements in one node to the storage units occupied by the entire node.

(2) The linked list is not a random storage structure and cannot be accessed randomly.


Third, the order table and the advantages and disadvantages of the list to cut the opposite, then in the practical application of how to choose the storage structure? There are usually several considerations:

(1) The storage space of the sequential table is statically allocated, before the program execution must clearly stipulate its storage scale, that is to say beforehand to "MaxSize" to have the appropriate setting, set up the conference to cause the waste of storage space, too small cause overflow. Therefore, when the length of the linear table or storage scale is difficult to estimate, it is not advisable to use sequential table. However, the dynamic allocation of a linked list can overcome this shortcoming. The list does not need to reserve storage space, do not need to know how to change the length of the table, as long as the memory space is still idle, you can re-run the program at any time to dynamically allocate space, do not need to also be dynamically recycled. Therefore, when the length of linear table changes greatly or it is difficult to estimate its storage size, dynamic linked list should be used as storage structure.

In a linked list, however, the sea requires additional pointers on each node in addition to the data outside the domain. If the node's data occupies a small space, the structural cost of the linked list takes up most of the storage space. When the order table is filled, there is no structural overhead. In this case, the spatial efficiency of the sequential table is higher. Because of the additional overhead of setting the pointer domain, the storage density of the list is less than 1 from the storage density point of view. Therefore, in order to save storage space, it is more appropriate to use sequential table as the storage structure when the length of linear table changes little and is easy to determine its size beforehand.

(2) Calculation-based considerations (time)

Sequential storage is a random access structure, and the linked list is a sequential access structure, so they have a completely different algorithm and time complexity for various operations. For example, to find the element I in a linear table, the address of a (i) can be computed directly for the order table, without the need to find a time complexity of 0 (1). The list must start from the list header and look backwards, averaging 0 (n). Therefore, if the operation is often done by ordinal access to data elements, it is clear that the table is better than the linked list.

Conversely, in the sequential table to do the insertion, delete the average half of the moving table elements, when the data elements of a large amount of information and the table is longer, this should not be overlooked; in the list of inserts, delete, although to find the insertion position, but the operation is a comparison operation, from this angle is obviously better than the former.

(3) Environment-based considerations (language)

Sequential tables are easy to implement, with array types in any high-level language, and linked list operations based on pointers. Relatively speaking, the former is simple, but also a factor of user consideration.

In short, the two storage structures each have a length, which is determined by the main factors in the actual problem. Usually "more stable" linear table, that is, the main operation is to find the operation of the linear table, suitable for the selection of sequential storage, and frequently do insert delete operations (that is, dynamic relatively strong) linear table suitable for the selection of chain storage.

Comparison of sequential storage structure and chained storage structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.