map vs unordered_map in C++
C++
| map | unordered_map
---------------------------------------------------------
Ordering | increasing order | no ordering
| (by default) |
Implementation | Self balancing BST | Hash Table
| like Red-Black Tree |
search time | log(n) | O(1) -> Average
| | O(n) -> Worst Case
Insertion time | log(n) + Rebalance | Same as search
Deletion time | log(n) + Rebalance | Same as search
::-> Use std::map when
1. You need ordered data.
2. You would have to print/access the data (in sorted order).
3. You need predecessor/successor of elements.
::-> Use std::unordered_map when
1. You need to keep count of some data (Example – strings) and no ordering is required.
2. You need single element access i.e. no traversal.
Also in C++:
- Title
- c++ client service ros
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- c++ uint32_t
- Category
- C++
- Title
- transpose matrix eigen c++
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- c++ throw exception
- Category
- C++
- Title
- string to vector c++
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- rgb(100,100,100,0.5) validation c++
- Category
- C++
- Title
- c++ get type name of object
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- unordered_set in c++ and ordered set diff
- Category
- C++
- Title
- statement that causes a function to end in c++
- Category
- C++
- Title
- preorder traversal c++
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- ue4 c++ struct
- Category
- C++
- Title
- c++ short if
- Category
- C++
- Title
- removing repeated characters in a string c++
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- convert decimal to binary in c++
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- Html tab
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- iterate const vector
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- : error: ‘cont’ cannot be used as a function return (cont(cont-1))/2;
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- c++ ternary operator
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- c++ bsod
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++
- Title
- class in c++
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- how to delete an element in vector pair in cpp
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- c++ sort
- Category
- C++
- Title
- regexp_like oracle c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- int max in c++
- Category
- C++
- Title
- how to get the prime number in c++ where time complexity is 0(log n)
- Category
- C++
- Title
- c++ cout int
- Category
- C++
- Title
- intersection between vector c++
- Category
- C++
- Title
- how to convert n space separated integers in c++
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- cannot jump from switch statement to this case label c++
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- heredar constructor c++
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- sub string of vector c++
- Category
- C++
- Title
- C++ while
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- sqrt cpp
- Category
- C++
- Title
- variable sized arrays hackerrank solution in c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- if not defined c++
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- c++ string
- Category
- C++
- Title
- what is a header in c++
- Category
- C++
- Title
- setbits
- Category
- C++
- Title
- c++ parse int
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- gta san andreas
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- c++ remove space from string
- Category
- C++
- Title
- how to remove maximum number of characters in c++ cin,ignore
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- sleep system function linux c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- minimum swaps to sort an array
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- if esle in c++
- Category
- C++
- Title
- how to convert qt string to string
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- creare array con c++
- Category
- C++