Difference between Array and Linked List
Difference between Array and Linked List
Hello Friends, Today we will tell you the difference between array and linked list, So let's start this guys.
Both Arrays and linked list are used for store the linear data but arrays allocate the contiguous memory location in Compile time while linked list allocate the memory in run time.
This is basic and most important difference .Now, we will read the other main difference,
- Array is an ordered collection of same data type but linked list is ordered collection of same type of element which is connected to each other by pointers.
- Array supports random access which means that we can access this directly by index.e.g. For 1st element arr[0] , for 7th element arr[6] etc. while Linked list supports sequential access which means that in linked list for access any elements/nodes we have to sequentially traverse the full list.
- Arrays store the elements in contiguous memory location while In linked list a new elements can be store anywhere.
- In Arrays, elements can access very fast and time complexity is O(1) While time complexity of linked list is O(n).
- In Arrays, insertion and deletion operation takes longer because memory locations are continuous and fixed but In Linked list, Insertion and deletion operation are very fast.
- In the Array memory allocates in compile time and it is also called Static memory allocation But in Linked list, memory allocates in run time and it is also called Dynamic memory allocation.
- In Array, each elements are free and we can access it through their index value but In linked list, Each node are pointed by before and next nodes.
- Array can be single dimensional , two dimensional or multi dimensional while Linked list can be linear (singly),doubly and circular.
- In array, the size of array is specified at the time of declaration but in linked list the size of linked list is increases in run time, as new node add in this.
Thank you!