[Python-Dev] Retrieve an arbitrary element from a set withoutremoving it (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Wed Nov 4 02:10:58 CET 2009
- Previous message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Next message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Greg Ewing <greg.ewing canterbury.ac.nz> writes:
> >>Picking a random element can be done in O(1) only if the data >>structure supports access by index, which Python's hash tables don't. > > Well, at the implementation level, they can. You'd just have to pick a new > random index until it points to a non-empty slot.
But that's hardly O(1).
It is, assuming that the set has a built-in minimum fill level (e.g. it always keeps at least x% of its entries filled), and the random generator is good.
(of course, it is "statistically O(1)", like lookups in a hash table actually)
Regards
Antoine.
- Previous message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Next message: [Python-Dev] Retrieve an arbitrary element from a set withoutremoving it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]