Skip to content
Related Articles
Open in App
Not now

Related Articles

Difference Between Vector and List

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 29 Jun, 2022
Improve Article
Save Article

Vector: Vector is a type of dynamic array which has the ability to resize automatically after insertion or deletion of elements. The elements in vector are placed in contiguous storage so that they can be accessed and traversed using iterators. Element is inserted at the end of the vector.

vector v;

List: List is a double linked sequence that supports both forward and backward traversal. The time taken in the insertion and deletion in the beginning, end and middle is constant. It has the non-contiguous memory and there is no pre-allocated memory.

list  l;


Below is a table of differences between Vector and List:

It has contiguous memory.While it has non-contiguous memory.
It is synchronized.While it is not synchronized.
Vector may have a default size.List does not have default size.
In vector, each element only requires the space for itself only.In list, each element requires extra space for the node which holds the element, including pointers to the next and previous elements in the list.
Insertion at the end requires constant time but insertion elsewhere is costly.Insertion is cheap no matter where in the list it occurs.
Vector is thread safe.List is not thread safe.
Deletion at the end of the vector needs constant time but for the rest it is O(n).Deletion is cheap no matter where in the list it occurs.
Random access of elements is possible.Random access of elements is not possible.
Iterators become invalid if elements are added to or removed from the vector.Iterators are valid if elements are added to or removed from the list.
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!