filmov
tv
map vs unordered map In C++
Показать описание
JOIN ME:
Time Lines
=========
0:05 Introduction
0:20 map VS unordered_map
In this video we will learn what is the basic difference between STL map and unordered_map in C++. They both belongs to standard template library (STL) and both are containers and store values in key value pair but there are so many difference when it comes to choose one over another one.
The map store data in order, it can be any order like ascending or descending that we can choose when map is instantiated, where as unordered_map has no order for storing data.
Map uses red-black tree to store data in it, where as unordered_map uses hash table to store the data.
Map has log(n) complexity to search data but as unordered_map uses hash it's complexity is way better than map and that is O(1) in average case but in worst case it can go upto O(n), but this is so rare case.
Map has same log(n) complexity for insertion and deletion and similarly for unordered_map it is O(1) on average and O(n) in worst case.
So the bottom line of the comparison is that if we need order to be maintained then map should be used otherwise if just the key value pair is required then unordered_map is sufficient and very fast also.
Do let me know if there is any further doubt in the video, i will definitely replay and try to solve all the doubts.
Thanks,
CppNuts
#mapvsunordered_map #std::map #std::unordered_map #stl #standardtemplatelibrary
Time Lines
=========
0:05 Introduction
0:20 map VS unordered_map
In this video we will learn what is the basic difference between STL map and unordered_map in C++. They both belongs to standard template library (STL) and both are containers and store values in key value pair but there are so many difference when it comes to choose one over another one.
The map store data in order, it can be any order like ascending or descending that we can choose when map is instantiated, where as unordered_map has no order for storing data.
Map uses red-black tree to store data in it, where as unordered_map uses hash table to store the data.
Map has log(n) complexity to search data but as unordered_map uses hash it's complexity is way better than map and that is O(1) in average case but in worst case it can go upto O(n), but this is so rare case.
Map has same log(n) complexity for insertion and deletion and similarly for unordered_map it is O(1) on average and O(n) in worst case.
So the bottom line of the comparison is that if we need order to be maintained then map should be used otherwise if just the key value pair is required then unordered_map is sufficient and very fast also.
Do let me know if there is any further doubt in the video, i will definitely replay and try to solve all the doubts.
Thanks,
CppNuts
#mapvsunordered_map #std::map #std::unordered_map #stl #standardtemplatelibrary
Комментарии