Difference between Array and Linked list

 Difference between Array and Linked List

=================================================================================

Difference between Array and Linked list




Array: Arrays store elements in contiguous memory locations, resulting in easily calculable addresses for the elements stored and this allows faster access to an element at a specific index.


Linked List: Linked lists are less rigid in their storage structure and elements are usually not stored in contiguous locations, hence they need to be stored with additional tags giving a reference to the next element. 


This difference in the data storage scheme decides which data structure would be more suitable for a given situation.


ARRAY

LINKED LIST

Array cannot grow or shrink dynamically. (realloc() is not efficient)

Linked List can grow or shrink dynamically.

Array has contiguous memory. Hence random access is possible.

Notes are not in contiguous memory. Hence only sequential access is allowed.

Arrays do not have memory overheads.

Linked lists have memory overheads eg. Each node contains address of “next” node.

Insert / delete at middle position needs to shift remaining elements. Hence will be slower.

Insert / delete at middle position needs to modify links (next/prev pointers). Hence will be faster.

To deal to fixed number of elements and frequent random access, arrays are better

To deal to dynamic number of elements and frequent insertion / deletion operators, linked list are better


Comments

Popular posts from this blog

TREE

STACK

Evaluation of postfix expression