I'm curious if there are any real-world scenarios where LinkedLists can outperform ArrayLists and ArrayDeques, considering the impact of caching. Theoretically, linked lists are quicker for insertions and deletions at the ends since those operations take constant time, while the array-based versions take linear time with respect to their size. However, I've heard that, in practice, array implementations tend to be faster primarily due to better memory management and cache locality. Given this, can anyone point out specific cases where LinkedLists might still shine, especially regarding performance under different cache conditions?
6 Answers
For real-time applications, if you’re looking for the root node, LinkedLists might offer some speed. But overall, they can’t compete with the efficiency of ArrayLists or ArrayDeques.
Honestly, it's tough to make a case for LinkedLists being faster. Even in extreme scenarios, like if you’re deleting elements from the start of a massive ArrayList, you'd be better off creating a new structure tailored to your needs. For smaller applications with just a few elements, the speed differences are practically negligible, and most systems wouldn’t even notice.
Definitely not! LinkedLists feel outdated nowadays. Most developers would steer clear of them unless they have a specific reason to use one.
If you’re iterating through a LinkedList and need to remove items from random locations, it might perform better than an ArrayList. But don't forget, with all that overhead from node pointers, using two ArrayLists could actually be more efficient overall!
Exactly! If order doesn’t matter, just swapping the last item with the one you want to remove can be much quicker.
At the end of the day, it really comes down to performance needs. It’s hard to differentiate between the two in most practical applications. Generally speaking, you won’t notice a significant difference unless you're working with large data sets.
You’re right about cache overhead. For smaller lists, ArrayLists really outperform LinkedLists. However, when you get into larger lists, the time complexity might favor LinkedLists for insertions and deletions. I think that threshold is around the hundreds or thousands, depending on the situation.

You’re correct! Moving elements in a continuous array is much faster than searching through nodes at random locations. Linked lists can really slow things down.