I am confused with the time complexity of these two algorithms.
//time complexity O(nlog(n))
public void usingTreeMap(){
Map map = ne
Insertion time complexity is typically defined on a per instance basis.
Average case:
Worst case:
In your code above since you are inserting multiple items, we need to distinguish how many elements are in the maps (n) vs. how many elements are being added to the maps (m). If the maps are initially empty, then your runtime above is correct. If they already have some elements, then the runtimes would be:
Avg Worst
Insert m elements into HashMap: O(m) O(mn)
Inset m elements into TreeMap: O(mlogn) O(mlogn)