[Data structure] comparison of sequence tables and linked lists

Source: Internet
Author: User

The sequential table and linked list have their respective lengths. Which storage structure is used in actual applications? This is determined based on the requirements and nature of the specific issue. There are usually the following considerations::
┌ ── ─ ┐
│ Sequence table │ linked list │
─ ── ┬ ── ─
│ Base │ minute │ static allocation. Before executing the program, you must specify │ dynamic allocation as long as the memory space is still idle, │
│ Specify the storage scale in │ with │. If the length of the linear table N is changed to │, no overflow will occur. Therefore, when the linear table │
│ Empty │ is large, it is difficult to determine the storage size of │ length change greatly, it is difficult to estimate its storage │
│ It is estimated that space will be wasted due to overhead. When it is estimated that the space is too large, dynamic linked list will be used as storage │
│ Test │ small and will increase the chance of Space overflow. │ Structure is good. │
│ Consider ── ─
│ Storage │ is 1. When the length of a linear table does not change much, │ <1 │
│ Storage │ it is easy to determine its size in advance, in order to save │
│ │ Storage space, sequence tables should be used as storage │
│ Degree │ structure. │
─ ── ┼ ── ─
│ Base │ storage │ random access structure, all nodes in the table are │ sequential access structure. nodes in the linked list must be │
│ In │ get │ can be directly obtained in O (1) Time │ from the beginning pointer along the chain scan can be obtained. │
│ When │ linear table operations are mainly to search, very │
│ Method │ when less insert and delete operations are performed, the Order │
│ Test │ prepare a storage structure. │
│ Consider ── ─
│ Insert and delete in the sequence table, and average │ insert and │ at any position in the linked list
│ In │, you only need to modify the pointer to move nearly half of the nodes in the table, especially for │ deletion. For frequency │
│ Delete │ when the amount of information on each node is large, the linear table inserted and deleted by mobile │ is recommended. │
│ The time overhead for division of │ nodes is considerable. │ Use a linked list for storage structure. If the table is inserted and │
│ Operate │ Delete mainly occurs at the beginning and end of the table, then │
│ As │ the single-cycle linked list indicated by the tail pointer should be │
─ ── ┴ ── ─

Storage Density(Storage density) refers to the ratio of the storage space occupied by node data to that occupied by the entire node structure, that is

Storage Density = (storage volume occupied by node data)/(total storage volume occupied by node structure)

The summary is as follows:

1. The length is not clear. Use a linked list.

2. the query frequency is much higher than that of modifying the sequence table and vice-linked list.

3. High linked list modification cost


[Data structure] comparison of sequence tables and linked lists

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.