Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

c++ - I'm intrested in finding the time complexity of a map with two keys

I am trying to convert the entire elements of a matrix in to a hashmap. for that what i tried is using map<pair<int,int>,int>mp;

where pair<int,int> are the array indices and the value is the value in the element of a matrix. so i tried this way mp[{i,j}]=value;

It works fine but what i am interested in is finding the time complexity .In general if there and n keys maping to a value what will be the time complexity and how.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just to clarify, map container in C++ is a tree-based structure. You mentioned using a hashmap. unordered_map is a hash-based container in C++.

As for the unordered_map (https://en.cppreference.com/w/cpp/container/unordered_map):

Unordered map is an associative container that contains key-value pairs with unique keys. Search, insertion, and removal of elements have average constant-time complexity.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...