0

When I access a value in std::map at a given key, does the map search for this value linearly by checking each key-value pair if the key match or does it access the requested value directly?

2

1 Answer 1

2

Neither. It will have to search through an index to find the value, but it will do that in a way, that is much more efficient than a linear search.

Typically, this is implemented using a Red-black tree and search time will be logarithmic to the number of elements in the map.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.