A data structure is a particular way of organizing data in a computer so that it can be used effectively.
For example, we can store a list of items having the same data-type using the array data structure.
What is Linked List?
Like arrays, Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at a contiguous location; the elements are linked using pointers.
Why Linked List?
1) The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance.
2) Inserting a new element in an array of elements is expensive because the room has to be created for the new elements and to create room existing elements have to be shifted.
For example, in a system, if we maintain a sorted list of IDs in an array id.
id = [1000, 1010, 1050, 2000, 2040].
So, addition, updation, deletion is difficult And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 and for deleting also to delete 1010 in id, everything after 1010 has to be moved.
Advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion
1) Random access is not allowed. So we cannot do binary search with linked lists efficiently with its default implementation.
2) Extra memory space for a pointer is required with each element of the list.
3) Not cache friendly. Since array elements are contiguous locations, there is locality of reference which is not there in case of linked lists.
#DataStructures #Arrays #LinkedList #Programming #Probyto #ProbytoAI
Subscribe and follow us for latest news in Data Science, Machine learning, technology and stay updated!