Array vs Linked List

Access: Random / Sequential

1. Array element can be randomly accessed using index

2. Random access for element of linked list costs O(n) time

3. Generally, in linked list, elements are accessed sequentially

Memory Structure

1. Elements of array is stored in contiguous memoery locations.

2. Elements of linked list is stored at any available location. But the pointer to the memory location is stored in Previous Node.

Insertion / Deletion

Array takes more time.

Linked list takes O(1) time.

Memory Allocation

1. For array, memory should be allocated at Compile-Time.

2. For linked list, memory can be allocated at Run-Time.

原文地址:https://www.cnblogs.com/ireneyanglan/p/4922274.html