Pages

4 May 2012

Vector Vs List

Vectors and Lists are belong to sequence containers of C++ Standard Template Library. Primary difference between two comes from the internal data-structure used by both,

Vector
Internally vector uses a dynamic array (continues block of memory), which grows in forward direction.
This means random access and insertion/deletion in the end is faster. However if we insert/delete at the beginning or middle, operations will take more time as entire contents needs to be pushed/moved.

List
List is realized as (doubly) linked list.
So insertion/deletion any where is faster, which internally works as altering next of linked list nodes. By default list doesn't support random access, and hence search inside list is slower.

No comments:

Post a Comment