- Sequence Containers:
- Vector.
- Just like the array in c language that random access runs in constant time.
- Implemented by the dynamic array ensuring that the amortized time of push_back and pop_back is constant time.
- Modify elements other then the last element run in O(n) time
- Deque.
- Random access runs in constant time as well
- Implemented by double dynamic array I guess thus can push and pop elements both at the end and the front in constant time
- Modify elements other than the first and last elements run in O(n) time.
- List
- Like linked list in c language that random access will runs in O(n) time
- Obviously that insert and delete element run in constant time
- Container Adapters:
- Stack and Queue.
- Priority Queue
- Associative Containers:
- Set.
- Implemented by binary search tree (not hash table), thus the time complexity of insert and erase are O(logn)
- Map
- The same method with set thus [ ] operator is O(logn)
- Unordered_Set and Unordered_Map
- New in C++11 that insert erase and [] operators run in O(1) or O(n)
- Implemented by hash table
- The advantage of set over unordered_set is set requires limited memory in proportion to the input size
My Blog List
A brief summary over STL Container
Here is a brief summary talking about common STL Container used in Leetcode problems.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Enter you comment