What is the time complexity of checking membership with 'in' on a set?
- A O(n)
- B O(log n)
- C O(1) on average
- D O(n log n)
Answer
O(1) on average
Sets use a hash table. Replacing a list membership test inside a loop with a set is a common fix for accidentally quadratic code.





