AfterAcademy Tech
•
07 Feb 2020

Array and Linked List are the two most used data structures. It's really important to understand and compare the advantages and disadvantages of both array and linked list. In this blog, we will compare these two linear data structures. So let’s get started.
To start of the things, we will take some parameters through which we can compare both the data structures.
Structure
Array and Linked list are used to store linear data of similar type but the major difference between them is related to their structure. Arrays are an index-based data structure where each element is associated with an index. On the other hand, Linked list relies on references of where the next element in the list is stored, the last element of the linked list refers to NULL denoting that its the end of the list.
Arrays

Linked List

Size
Arrays have fixed size and it is required to know the size of the array at the time of declaration whereas Linked List is not restricted to size and can be expanded during the execution. So, Linked lists are dynamic, flexible.
Memory Required
The memory required to store data in the linked list is more than that of an array because of additional memory used to store the address/references of the next node.
Storage Allocation
In an array, memory is assigned during compile time while in a Linked list it is allocated during execution or runtime.
The elements in the array are stored at contiguous positions in the memory whereas the elements in the linked list are stored at random positions.
Accessing Time
Elements in the array can be accessed using it’s index i.e. if you want to get into the fourth element you have to write the array variable name with its index or location within the square bracket. But, in a linked list, you have to start from the head and iterate until you get to the fourth element.
The elements in an array can be directly and sequentially accessed but in a linked list only sequential access is possible. To conclude, accessing an element in an array is fast and is a constant time operation whereas, in a linked list, it takes linear time.
Memory utilization
Memory utilization is inefficient in the array as we need to declare the size of the array during the time of declaration. Conversely, memory utilization is efficient in the linked list.
Insertion/ Deletion
Operations like insertion and deletion in arrays consume a lot of time as shifting of elements are required but these operations are easy, fast and efficient in linked lists.
From the above points, we can conclude that Array and Linked lists are the types of data structures that differ in their structure, accessing and manipulation methods, memory requirement, and utilization and have particular advantages and disadvantages over its implementation.
Linked List: Dynamic Size, Fast insertion, and deletion once the element is reached
Arrays: Fast Random element access and requires less memory per element
Happy coding! Enjoy Algorithms.
AfterAcademy Tech
In this blog, we will discuss the types of linked list and basic operations that can be performed on a linked list.

AfterAcademy Tech
The problem is about reversing a Linked List. We are given the head node of the Linked List and we have to return the reversed Linked List's head. This is an interview problem asked in companies like Microsoft, Amazon and Adobe.

AfterAcademy Tech
Given a non-empty, singly linked list with head node head, write a program to return a middle node of linked list. If there are even nodes, then there would be two middle nodes, we need to print second middle element.

AfterAcademy Tech
Given a binary tree, flatten it to a linked list in-place. After flattening, the left of each node should point to NULL and right should contain the next node in level order so that it resembles a singly linked list.
