Time Complexity of OrderedSet() in python

2.6k Views Asked by At

I was going through this answer on Stack Overflow. I came to know about existence of OrderedSet in Python. I would like to know how it is implemented internally. Is it similar to hash table implementation of sets?

Also, what is the time complexity of some of the common operations like insert, delete, find, etc.?

1

There are 1 best solutions below

0
teoML On BEST ANSWER

From the documentation available here

Implementation based on a doubly linked link and an internal dictionary. This design gives OrderedSet the same big-Oh running times as regular sets including O(1) adds, removes, and lookups as well as O(n) iteration.

There is also a discussion on the topic, see Does Python have an ordered set?