Skip to content

Instantly share code, notes, and snippets.

@EricGustin
Created August 2, 2020 03:41
Show Gist options
  • Select an option

  • Save EricGustin/cd32ae2163135586a1ab506c5dce08d9 to your computer and use it in GitHub Desktop.

Select an option

Save EricGustin/cd32ae2163135586a1ab506c5dce08d9 to your computer and use it in GitHub Desktop.
Operation Example Big O Time Complexity
Length: len(s) O(1)
Add: s.add(2) O(1)
Contains: x in/not in s O(1)
Remove: s.remove(2) O(1)
Discard: s.discard(2) O(1)
Pop: s.pop() O(1)
Clear: s.clear() O(1)
Construct: set(iterable) O(length of iterable)
Iterate: for v in s: O(n)
Copy: s.copy() O(n)
Equal/Not Equal: s1 == s2 O(min(len(s1), len(s2)))
Comparison: s1 <= s2 O(len(s1))
Bitwise or: s1 | s2 O(len(s1)+len(s2))
Bitwise and: s1 & s2 O(min(len(s), len(t)))
Difference: s1 - s2 O(len(s2))
Bitwise xor: s1 ^ s2 O(len(s))
Iteration: for v in s: O(n)
Copy: s.copy() O(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment