Time complexity of TreeMap<> operations: get() and subMap()
Based on this post, Time complexity of TreeMap operations- subMap, headMap, tailMap subMap() itself is O(1), and O(n) comes from iterating the sub map. So, why use get(key) then? We can use subMap(key, true, key, true) instead, which is O(1) and iterating this sub map is also O(1). Faster than get(key), which is O(log(n)). Something wrong here... We can use subMap(key, true, key, true) instead, which is O(1) This is correct and iterating this sub map is also O(1). O(n) comes from the question. The answer says nothing to imply this, which is good, because it's not true. Time complexity of