Linked List v/s Array
Key Differences Between Array and Linked List
1. In the array the elements belong to indexes, i.e., if you want to get into the
fourth element you have to write the variable name with its index or location within the
square bracket.
2. In a linked list you have to start from the head and work your way through until you get
to the fourth element.
3. Accessing an element in an array is fast, while Linked list takes linear time,
so it is quite a bit slower.
4. Operations like insertion and deletion in arrays consume a lot of time. On the other
hand, the performance of these operations in Linked lists is fast.
Contd..
• Arrays are of fixed size. In contrast, Linked lists are dynamic and flexible and can
expand and contract its size.
• In an array, memory is assigned during compile time while in a Linked list it is
allocated during execution or runtime.
• Elements are stored consecutively in arrays whereas it is stored randomly in Linked
lists.
• The requirement of memory is less in case of an ARRAY due to actual data being
stored within the index in the array whereas linked list need more memory due to
storage of additional next and previous pointers.
• memory utilization is inefficient in the array whereas memory utilization is efficient in
the linked list.
Advantages of Linked list over Array
Linked list advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion
Linked lists have following drawbacks
• 1) Random access is not allowed. We have to access elements
sequentially starting from the first node.
so, Traversal takes o(n) time whereas in an array it is done in O(1)
time
• 2) Extra memory space for a pointer is required with each element of
the linked list.
Advantages/ Disadvantages of SLL over DLL
• Advantages of DLL over SLL
1) A DLL can be traversed in both forward and backward direction.
2) The delete operation in DLL is more efficient if pointer to the node to be deleted is
given.
3) We can quickly insert a new node before a given node.
In singly linked list, to delete a node, pointer to the previous node is needed. To get
this previous node, sometimes the list is traversed. In DLL, we can get the previous
node using previous pointer.
Advantages/ Disadvantages of SLL over DLL
•
Disadvantages of DLL over SLL
1) Every node of DLL Require extra space for an previous
pointer.
2) All operations require an extra pointer previous to be
maintained. For example, in insertion, we need to modify previous
pointers together with next pointers
Applications of linked list in computer
science
1.Implementation of stacks and queues
2.Implementation of graphs : Adjacency list representation of graphs is
most popular which is uses linked list to store adjacent vertices.
3.Dynamic memory allocation : We use linked list of free blocks.
4.Maintaining directory of names
5.Performing arithmetic operations on long integers
6.Manipulation of polynomials by storing constants in the node of linked
list
7.representing sparse matrices
Applications of linked list in real world-
1.Image viewer – Previous and next images are linked, hence can
be accessed by next and previous button.
2.Previous and next page in web browser – We can access
previous and next url searched in web browser by pressing back
and next button since, they are linked as linked list.
3.Music Player – Songs in music player are linked to previous and
next song. you can play songs either from starting or ending of
the list.
Applications of Circular Linked Lists:
1.Useful for implementation of queue.
• we don’t need to maintain two pointers for front and rear if we use
circular linked list.
• We can maintain a pointer to the last inserted node and front can
always be obtained as next of last.
2.Circular lists are useful in applications to repeatedly go around the
list. (Round robin scheduling of processes)
It is convenient for the operating system to use a circular list so that
when it reaches the end of the list it can cycle around to the front of
the list.