Comparison of the advantages and disadvantages of sequence table (array) and linked list, with examples of cache utilization

1. Sequence table (array)

Disadvantages:

1.头部或中间插入删除数据需要挪动数据,时间复杂度为O(N)
2.空间不够了需要增容,增容有一些消耗。其次增容一般是2倍,
那么就有可能存在一定的空间浪费

advantage:

1.相对而言空间利用率更高,不需要额外的空间,占用空间小;
链表需要存指针
2.物理空间是连续的。
a.支持随机访问,可以用下标访问(最大的优势)
b.相比链表结构,缓存命中率比较高,访问更高效

2. Two-way leading circular linked list

Disadvantages:

不支持随机访问,缓存命中相对较低

advantage:

支持任意位置O(1)插入删除,不需要增容,不存在空间浪费

Linked list and sequence list are two complementary data structures that complement each other

3. Examples of cache utilization

eg: Suppose that the array and the linked list are traversed separately, and the data in the array and the linked list *2

CPU fetches data to perform operations, first see if the data is in the cache
(1) in (cache hit), directly calculate, and then write back to the memory
(2) not in (cache hit), load data from the memory to the cache ( 加载一段连续内存数据), then calculate, and then Write back to memory
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_50886514/article/details/113822519