I am writing a lazy propagation code using the segment tree data structures. For doing the lazy propagation I wanted to store a list of integers at a node in the segment tree and while carrying the lazy propagation I wanted to append the list of integers of the node to the left and the right children. In order to maintain the complexity of the update method in Segment Trees to Log(n) time I wanted to do the lazy update at a node in O(1) time. So for storing the list of integers I can use Vectors or LinkedList in Java. Vectors in java have a method called addAll and LinkedList also has the same method. Could anyone please suggest me which one of two would be more optimized for just adding all elements of one list to another. Thanks
Asked
Active
Viewed 287 times
0
-
Don't use `Vector`, it's obsolete. If you need thread safety, use a `CopyOnWriteArrayList`, otherwise a plain `ArrayList` will do. – fge Mar 12 '14 at 09:19
-
Ok. I wrote Vector because the functionality of ArrayList and vector are the same in Java. Will addAll method in ArrayList have a constant time adding of all elements of one ArrayList to another? – user1580096 Mar 12 '14 at 09:31
-
addAll() in ArrayList and LinkedList have linear time complexity. – Eyal Schneider Mar 12 '14 at 09:54