(i) Comparison of the advantages and disadvantages of sequential storage structures and chained storage structures, as well as usage scenarios.
1 Advantages and disadvantages
① sequential storage, the storage address of adjacent data elements is also adjacent (logical and physical unification); requires that the address of the memory available storage unit must be contiguous.
Advantages: Large storage density (=1), high storage space utilization. Cons: inconvenient when inserting or deleting elements.
② chain storage, the adjacent data elements can be stored at will, but the storage space is divided into two parts, part of the node value, and the other part of the node to represent the relationship between the pointer
Pros: Easy to insert or delete elements, flexible to use. Disadvantage: Small storage density (<1), low storage space utilization.
2 Use Cases
Sequential tables are suitable for static operations such as searching, and lists are appropriate for inserting and deleting such dynamic operations.
If the length of the linear table changes little, and its main operation is to find, then the sequential table is adopted;
If the length of the linear table varies greatly, and its main operation is insert, delete operation, then the linked list is adopted.
3 comparison
Comparison of sequential tables and linked lists
Space-based comparisons
How storage is allocated
The storage space of the sequential table is statically allocated
The storage space of a linked list is dynamically allocated
Storage density = Total amount of storage/node structure occupied by the node data itself
Storage density of sequential tables = 1
Storage density of the linked list < 1
Time-based comparisons
Access mode
Sequential tables can be accessed randomly or sequentially.
The linked list is sequential access
Number of elements moved when inserting/deleting
The average order table needs to move nearly half of the elements
Linked list does not need to move elements, only need to modify pointers