Javatpoint Logo

Why insertion and deletion in ArrayList is slow compared to LinkedList ?

By: sIma12*** On: Mon Jan 07 22:45:47 IST 2013     Question Reputation5 Answer Reputation0 Quiz Belt Series Points0  5Blank User
RstudrurtUp0Down

 
ArrayList internally uses and array to store the elements, when that array gets filled by inserting elements a new array of roughly 1.5 times the size of the original array is created and all the data of old array is copied to new array.
During deletion, all elements present in the array after the deleted elements have to be moved one step back to fill the space created by deletion. In linked list data is stored in nodes that have reference to the previous node and the next node so adding element is simple as creating the node an updating the next pointer on the last node and the previous pointer on the new node. Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.
Image Created0Down

By: [email protected] On: Tue Jan 08 11:27:29 IST 2013 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes1No