in reply to What makes an array sorted and a hash unsorted?
I would not use the term sorted, I would use the term ordered.
This distinction is perhaps more obvious when you look at another way to map a string to a value. The two approaches I'm familiar with are binary trees and hash tables.
In the case of a binary tree, the items are ordered because the structure of the tree imposes an intrinsic order on the data. Hashes, on the other hand, are intrinsically not ordered internally. In fact, this feature is what allows for (relatively) inexpensive insertion and deletion. (Two items with keys very close to each other are likely to end up in different areas of the hash table.)
As you said, the interface we see for the hash could be changed to return the data in an ordered fashion, but the data structure is still intrinsically unordered.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: What makes an array sorted and a hash unsorted?
by Fletch (Bishop) on Jun 01, 2009 at 21:46 UTC | |
Re^2: What makes an array sorted and a hash unsorted?
by JavaFan (Canon) on Jun 01, 2009 at 23:29 UTC | |
by gwadej (Chaplain) on Jun 02, 2009 at 03:40 UTC | |
by herveus (Prior) on Jun 02, 2009 at 12:32 UTC | |
by JavaFan (Canon) on Jun 02, 2009 at 15:03 UTC | |
by herveus (Prior) on Jun 03, 2009 at 13:31 UTC | |
by JavaFan (Canon) on Jun 03, 2009 at 15:18 UTC | |
| |
by JavaFan (Canon) on Jun 03, 2009 at 14:00 UTC | |
|