Skip to content

Instantly share code, notes, and snippets.

@Trevahok
Last active July 31, 2020 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trevahok/eb5e499ebb0971eb90fad056a172c891 to your computer and use it in GitHub Desktop.
Save Trevahok/eb5e499ebb0971eb90fad056a172c891 to your computer and use it in GitHub Desktop.
Function Creation Insertion Updation Deletion Search Notes
vector O(n) O(1) O(1) O(n) O(n) Insertion and deletion inbetween is heavy, push_back and pop_back is amortized to O(1)
deque O(1) O(1) O(1) O(1) O(n) Insertion nad deletion is possible at both ends of the list
stack O(1) O(1) NA O(1) O(n) Insertion and deletion is possible only at the top
queue O(1) O(1) NA O(1) O(n) Insertion at back and deletion at front
unordered_map O(1) O(1) O(1) O(1) O(1) Can't store duplicates
unordered_set O(1) O(1) O(1) O(1) O(1) Can't store duplicates
priority_queue O(1) O(logn) NA O(logn) O(nlogn) Random access is not possible
map<K,V> O(1) O(logn) O(logn) O(logn) O(logn) No duplicates and slower than unordered_map
set O(1) O(logn) NA O(logn) O(logn) No duplicates and slower than unordered_set
multiset O(1) O(logn) O(logn) O(logn) O(logn) Slower than unordered_set but can store duplicates
bitset<> O(1) O(1) O(1) O(1) O(1) Can not resize; can store only 0 or 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment