Reputation: 133
For the nested map like :
Map<String, Map<String, List<String>>> map = new HashMap<String, HashMap<String, ArrayList<String>>>();
What would the time complexity be for its normal operation like put, remove, containsKey?
Thanks!
Upvotes: 1
Views: 986
Reputation: 393811
The time complexity would be the same as the time complexity of non-nested HashMap
s.
Each lookup still takes average constant time.
To search for an inner value in the nested Map
you need to perform two lookups - the first in the outer Map
, and if a value was found in the outer Map
, a second lookup in the inner Map
. Since both lookup will take constant time, the total lookup time remains constant.
The same is true for put
, remove
, etc...
Upvotes: 3