I have a basic tree/algorithm question for Java:
Say I am constructing a new TreeMap:
TreeMap<KeyType,ValType> myTreeMap = new TreeMap<>();
And I also have an existing array of data that is already in Comparison order:
KeyType myArray[] = new KeyType[]{.......};
Is there a way to populate the TreeMap with this data in O(n) time? I.e., is this the most efficient method:
for (int i = 0; i < myArray.length; i++){
myTreeMap.put(myArray[i],"blah");
}
Or is there a way to take advantage of the fact that the data is already in order to avoid a possible O(lg n) insertions/tree-balancing?