In this blog post will study what is linked lists, arrays vs linked lists, advantages and disadvantages of linked lists, operations, types and applications of linked lists.
A linked list is a linear data structure used for storing
collections of data. It consists of nodes where each node
contains a data field and a reference(link) to the next node
in the list.
A linked list has the following properties:
Advantages
The main advantage of linked lists is that they can be expanded in constant time. To create an array, we must allocate memory for a certain number of elements. To add more elements to the array when full, we must create a new array and copy the old array into the new array. This can take a lot of time.
Disadvantages
The main disadvantage of linked lists is access time to individual elements. Array is random-access, which means it takes O(1) to access any element in the array. Linked lists take O(n) for access to an element in the list in the worst case. Another advantage of arrays in access time is spacial locality in memory.
Sometimes linked lists are hard to manipulate. If the last item is deleted, the last but one must then have its pointer changed to hold a NULL reference. This requires that the list is traversed to find the last but one link, and its pointer set to a NULL reference.
We will study each of this type in separate blog posts.
That's it from this blog post. If you liked it then do share this blog with your friends or people who wanna get into programming world. Thank You!