4 ms·
> this is assuming you consider a hash table lookup to take constant time That's exactly the part I was referring to. If deleting the key from an OrderedDict i
by viraptor 17y ago
> this is assuming you consider a hash table lookup to take constant time
That's exactly the part I was referring to. If deleting the key from an OrderedDict is O(1), then all these operations have to be O(1):
- dictionary deletion
- _map.pop (which is another dictionary deletion)
- linked list removal (obvious)
I'm not saying they aren't - just wanted to make sure that's the case. I didn't know whether to interpret the sentence from "what's new" as - "we use a map to know the elements, so the only operation on a linked list is unlink, which is O(1)", or "the whole lookup+delete is O(1)".
- alxv 17y agoThe dictionary implementation of Python is a hash table using open addressing with quadratic probing. Deletion is essentially a lookup to replace the key with a tombstone. And, the table is never resized after a deletion. So yes, the whole operation is O(1) on average.
- andrewcooke 17y agoi think the confusion here is whether we're talking about worst case or average times. cuckoo hashing addresses worst case times, while the traditional O(1) for access to a probed table is an average time (worst case is going to be O(n) i guess). that's not as bad as it sounds because provided the load factor is low enough the probability of the worst case goes down "fast enough" for the average to be bounded. i think :o)