I think, when analysing the complexity, you need to take into account the metric you are using. In the ArrayList
, your metric is shuffling
, which is just assignment. But this is quite a complex operation.
On the other hand, you're using a LinkedList
, and you're simply looking going to the reference. In fact, you only perform 1 insertion. So while the algorithmic complexity will wind up similar, the actual processes that are being executed at O(n)
time are different. In the case of an ArrayList
, it is performing a lot of memory manipulation. In the case of a LinkedList
, it's only reading.
For those saying he doesn't understand LinkedLists
A LinkedList only has a pointed at the start, and a pointer at the end. It does not automatically know the Node behind the node you want to delete (unless it's a doubly linked list) so you need to traverse through the list, from the start by creating a temp pointer, until you come to the node before the one you want to delete, and I believe it's this that OP is discussing.