I read a previous question about the time complexity for TreeSet and the answer was that it takes O(n) time. However, I don't understand why it is O(n) to iterate instead of O(n*nlogn).
Each next call takes O(logn) time
So if I iterate through a TreeSet like this:
while (iterator.hasNext()){ //Runs N times
System.out.println(iterator.next() + " "); //each next is O(logn)
}
I would expect for it to be O(n*logn) and not O(n) because the while loop has N iterations and each iterator.next() call takes O(logn) time.