2 ms·
"Balanced binary tree versus hash table is an implementation choice for the associative array abstract data type." You can treat it as an implementation detail
by shadowmatter 16y ago
"Balanced binary tree versus hash table is an implementation choice for the associative array abstract data type."
You can treat it as an implementation detail, but it's a good idea to let the client know that the underlying key-value collection is actually sorted by key. This allows the client to iterate over the key-value pairs in sorted order without dumping the keys to an array and then sorting it, retrieving the k smallest keys through forward iteration, retrieving the k largest keys through reverse iteration, etc. I think Java solves this nicely by creating the SortedMap subinterface of Map; if you have a SortedMap, you're assured these properties hold. (The typical implementation of SortedMap is a balanced tree, while the typical implementation of Map is a hash table.)