You're right. Hashtables are sorted by some hash function, not by their natural sort order, so you will need to extract all O (N) entries and sort them O (NlogN), while you can traverse the binary search tree in a natural order in O (N )
Please note, however, that in Java, for example, there is a LinkedHashSet and LinkedHashMap, which gives you some advantages of the Hash, but which can be traversed in the order in which it was added so that you can sort it and be able to go through it in this sorted order as well as hash extraction.
Paul tomblin
source share