Skip to content
UPEEC

map and unordered_map

Key–value containers: map keeps keys sorted (tree), unordered_map uses hashing for faster lookups.

Intermediate
Comments 0
std::unordered_map<std::string, int> pins = {{"LED", 13}, {"BUZZER", 8}};
pins["SERVO"] = 9;
if (auto it = pins.find("LED"); it != pins.end())
    std::cout << it->second;    // 13
mapunordered_map
Ordersorted by keynone
LookupO(log⁡n)O(\log n)O(1)O(1) average

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.