Data Structures | Linked List | Question 2
Which of the following points is/are true about Linked List data structure when it is compared with array?
Arrays have better cache locality that can make them better in terms of performance.
It is easy to insert and delete elements in Linked List
Random access is not allowed in a typical implementation of Linked Lists
The size of array has to be pre-decided, linked lists can change their size any time.
All of the above
The following points are true when comparing Linked List data structure with an array:
Insertion and deletion: Linked lists allow for efficient insertion and deletion operations at any point in the list, as they involve simply adjusting pointers, while in an array, these operations can be expensive as all the elements after the insertion or deletion point need to be shifted.
Memory allocation: Linked lists use dynamic memory allocation, so they can grow or shrink as needed, while arrays have a fixed size and need to be allocated a contiguous block of memory upfront.
Access time: Arrays provide constant-time access to any element in the array (assuming the index is known), while accessing an element in a linked list takes linear time proportional to the number of elements in the list, as the list needs to be traversed from the beginning to find the desired element.
Random access: Arrays support random access, which means that we can directly access any element in the array with its index, while linked lists do not support random access and we need to traverse the list to find a specific element.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Please Login to comment...