Comparison of the performance of sequential tables and linked lists in data structures

Source: Internet
Author: User

One, the comparison of time performance

The sequential table is implemented by an array, which is a random access structure, and the complexity of the access operation time of any node in the table is O (1).

To find the nodes of a linked list, you should scan the chain from the beginning, and the average time complexity is O (N). Therefore, if the operation of the linear table is mainly to find, rarely insert or delete operations, the use of the order is more appropriate.

For a linked list, an insert delete operation on a node simply modifies the pointer, eliminating the need for a large number of moving elements, with an average time complexity of O (1). The sequential table, when inserted or deleted, requires a large number of moving data elements, the average number of moving elements is the general length of the table, and the time complexity is O (N). Therefore, a linked list should be used when inserting and deleting a linear table frequently. Circular lists should be used when insertions and deletions are primarily in the header or footer of a table.

Table 1: Comparison of time performance

Complexity of Time

Find

Insert or delete

Sequential table

O (1)

O (N)

Linked list

O (N)

O (1)

Second, the comparison of space performance

1, the storage space of the sequential table is statically allocated, and its memory size must be determined in advance. It is often used to store linear tables with easy sizing.

2, the dynamic list of storage space is dynamically allocated, as long as its memory space is free, there will be no overflow. It is often used for linear tables with large variations in length or difficulty in estimating length.

3, definition: storage density = (space occupied by data fields in the node)/(storage space occupied by node structure)

Sometimes you need to consider storage density.

In conclusion, when selecting linear table, the time and space factors should be taken into consideration, and the most suitable one should be chosen. In general, sequential tables are useful for queries, and linked lists make it easier to insert delete management.

Comparison of the performance of sequential tables and linked lists in data structures

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.