From 24eaec6e4491aa9fec6e546f712d06c3b879cc55 Mon Sep 17 00:00:00 2001 From: shreyas1599 Date: Tue, 20 Aug 2019 20:31:07 +0530 Subject: [PATCH] [Update] Added guide for unordered_map (#36608) * [Update] Added guide for unordered_map * fix: removed unsecure links --- guide/english/cplusplus/map/index.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/guide/english/cplusplus/map/index.md b/guide/english/cplusplus/map/index.md index d4659e05ee..5376574018 100644 --- a/guide/english/cplusplus/map/index.md +++ b/guide/english/cplusplus/map/index.md @@ -121,8 +121,20 @@ for(it=first.begin(); it!=first.end(); ++it){ } ``` -Here you can learn more about map: cpluspluc_map - N.B: All code in example are in C++11 version. You can learn more about C++ version Here +## Unordered Map +There exists another associative container similar to `map`, named `unordered_map`, which is implemented using a Hash Table as opposed to a balanced binary tree as is the case with `map`. The key values of the `unordered_map` are hashed into indices of the hash table. Unlike `map` the elements of `unordered_map` are not stored in a sorted manner. All operations permissible on `map` are applicable to `unordered_map` as well. + +## Benefits of Unordered Map +* Average Cost of insert, delete, search is O(1) if there are no hash collisions. +* Implemented using Hash Table + +## Unordered Map vs Map +* Unordered Map is faster if you want single element access. +* Use map when you want to traverse through key values in a sorted fashion or if you want some kind of ordering in the map. +* Unordered Map has more memory overhead, although it is typically negligible. + +## References: +For more information about the differences between `map` and `unordered_map`: Map vs Unordered Map