Amazon Interview Question

What is the difference between a Linked List and an array list.

Interview Answer

Anonymous

Apr 24, 2019

In terms of operations and memory space they differ a lot. A Linked List takes O(1) time complexity to prepend and an array list takes O(n). To append, a Linked List takes O(1) if you have a tail pointer, else O(n) if you need to traverse to the end of the list in order to append the new node, and an arraylist that is fixed-sized and not full will only take O(1) while a dynamic, and full arraylist will take O(n). Searching for a particular value, and popping a specific index both takes O(n) for both Linked List and array list. Resizing the Linked List only takes O(1) because it's as simple as removing the connection of a node, or creating a new connection of a node, however it takes O(n) for an array list because it must create a whole new resized fixed list and append everything into that new resized fixed list. Another thing is that the linked list does not require contiguous memory space like the array does because it is merely only the nodes referencing another node, and this could be useful in cases where you don't have a contiguous memory space to make an array of a fixed size.

1