I've been spending a lot of time going back and forth on whether I should use a vector or a linked list. I've been reading many completely contradicting views on the topic, so I'd like a strait up answer based on TODAY'S hardware in the REAL world.
So I've been told that if you are doing a lot of insertion and deletion in the middle of your sequence, a linked list would be ideal, with a complexity of O(1)
(which in itself I don't fully understand, since you have to traverse all the way to the desired location anyway) while insertion into a vector is apparently very slow, with a complexity of O(n)
On the other hand, after watching this lecture by Bjarne Stroustrup https://www.youtube.com/watch?v=YQs6IC-vgmo it seems as though there is no real use for linked lists, and using linked lists because there will be a lot of insertion and deletion would really only be implemented by a naive student. What I got from this is that essentially by the nature of the traverse of a linked list it is performing random access several times as it travels through different locations in memory, while a vector performs random access once, sending you directly to the desired location. Is this Interpretation accurate?
In my implementation, the sequence is to maintain order, being updated with new values for each element every frame, hence, a lot of deletion and insertion.
My question is: is there really any use for a linked list anymore? Even if it is to maintain order and than simply be run strait through?
background info:
- the sequence is for a 2D sweep and prune broad phase collision detection;
- the upper bound of number of elements in the sequence would be about 30,000