map vs unordered map In C++

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

i only came to learn about ordered/unordered map but i also gained knowledge about ordeRRR and unorderRRRed map, thanks 😊

anupamsharma
Автор

is the same difference we have for set and unordered_set as well?

ChandraShekhar-bycd
Автор

Thanks a lot for this informative video, it is usually asked in interview question and sometime I missed this question and get the rejection.

ChandraShekhar-bycd
Автор

voice is very low as compared to your other videos.

piyushmalaviya
Автор

Only indians will make a video to explain something that can be written in two paragraphs. I knew rhis before I click thw video. I just did it to prove it to myself

MegaKalkas