Posts

Showing posts with the label Linked List vs Array

Linked List vs Array | Data Structures and Algorithm.

Image
  Arrays   store elements in contiguous memory locations, resulting in easily calculable addresses for the elements stored and this allows a faster access to an element at a specific index.   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.  Data storage scheme of an array Data storage scheme of a linked list   Major differences are listed below:  Size:   Since data can only be stored in contiguous blocks of memory in an array, its size cannot be altered at runtime due to risk of overwriting over other data. However in a linked list, each node points to the next one such that data can exist at scattered (non-contiguous) addresses; this allows for a dynamic size which can change at runtime. Memory allocation:  For