Explain the difference between array and linked list?
S.no | ARRAYS | LINKED LIST |
---|---|---|
1. | An array is a collection of the elements of a similar data type. | Linked List is an ordered collection of the elements of the same type and all the elements, with the help of pointer, are connected. |
2. | The array supports the Random Access. Here the elements can be accessed directly using their index, like arr[2] for the 3rd element, arr[1] for the 2nd element, arr[0] for the 1st element, etc. | Linked List supports the Sequential Access. Here to access any element or node in a linked list, we have to sequentially traverse the complete linked list to reach to that element. |
3. | In an array, elements are stored consecutively in the memory. | In a linked list, the new elements can be stored anywhere in the memory. |
BY Best Interview Question ON 02 Feb 2019