The python wiki on time complexity lists a single intersection as O(min(len(s), len(t)) where s and t are sets with the sizes len(s) and len(t), respectively. (In English: the time is bounded by and linear in the size of the smaller set.)

Note: based on the comments below, this wiki entry had been be wrong if the argument passed is not a set. I've corrected the wiki entry.

If you have n sets (sets, not iterables), you'll do n-1 intersections and the time can be (n-1)O(len(s)) where s is the set with the smallest size.

Note that as you do an intersection the result may get smaller, so although O is the worst case, in practice, the time will be better than this.

However, looking at the specific code this idea of taking the min() only applies to a single pair of sets and doesn't extend to multiple sets. So in this case, we have to be pessimistic and take s as the set with the largest size.

Answer from rocky on Stack Overflow
๐ŸŒ
Python-bloggers
python-bloggers.com โ€บ 2022 โ€บ 02 โ€บ python-set-intersection-the-ultimate-guide-for-beginners
Python Set Intersection โ€“ The Ultimate Guide for Beginners | Python-bloggers
February 7, 2022 - The time complexity of set intersection in Python on a set with n elements and a set argument with m elements is O(min(n, m)) because you need to check for the smaller set whether each of its elements is a member of the larger set.
Discussions

python - Intersection complexity - Stack Overflow
Given a large table and a randomized ... of the intersection algorithm "losing" are infinitesimally low and likely to never occur. 2022-09-01T14:53:29.527Z+00:00 ... Save this answer. ... Show activity on this post. The answer appears to be a search engine query away. You can also use this direct link to the Time Complexity page at python.o... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Time complexity of python set operations?
Python sets are powerful data ... tables, similar to dictionaries in Python but only storing keys without associated values. Due to their hash table implementation, most of the common operations on sets have efficient time complexities.... More on designgurus.io
๐ŸŒ designgurus.io
1
10
June 21, 2024
algorithms - Time complexity of set intersection - Computer Science Stack Exchange
This problem involves the time-complexity of determining set intersections, and the algorithm must give output on all possible inputs (as described below). Problem 1: The input is a positive in... More on cs.stackexchange.com
๐ŸŒ cs.stackexchange.com
August 6, 2018
What's the fastest algorithm and data structure for set operations like intersection?
Let's say there are m elements in the first set, and n in the second set. In general, there's no way to find the result faster than O(m + n). (For some specific problems there may be a faster solution depending on what type of stuff is in the set.) So the main question is how to achieve O(m + n). The most common solution is to use a HashSet. For example: Insert all of the items from the first set (or the smaller set) into a HashSet. Then iterate over all of the items in the second set and test if any of them are in the HashSet. If so, add them to the intersection. Hash tables are generally O(1) to insert and look up. If you're not familiar with them I'd highly recommend learning how they work. More on reddit.com
๐ŸŒ r/learnprogramming
7
1
March 8, 2023
People also ask

What happens if the input elements are not hashable?
If the elements within the arrays (e.g., nested lists, custom objects without a defined __hash__ method) are not hashable, the set-based solution will fail with a TypeError. In such cases, if hashing is impossible, the Sorting and Two Pointers approach (O(N log N)) becomes the most efficient fallback, as it relies only on comparison.
๐ŸŒ
technetexperts.com
technetexperts.com โ€บ home โ€บ optimizing array intersection to o(n+m) complexity
Optimizing Array Intersection to O(n+m) Complexity
Why is the complexity cited as O(N+M) rather than O(N)?
The time complexity is O(N+M) because you must account for the time spent constructing the hash tables (sets) from the input lists. If list A has N elements and list B has M elements, building set(A) takes O(N) time and building set(B) takes O(M) time. Even though the intersection calculation itself is very fast (O(min(N, M))), the preparation step dominates the initial cost, resulting in a total cost proportional to the sum of the input sizes.
๐ŸŒ
technetexperts.com
technetexperts.com โ€บ home โ€บ optimizing array intersection to o(n+m) complexity
Optimizing Array Intersection to O(n+m) Complexity
Is there overhead associated with hashing?
Yes. Hash tables require memory overhead for storing the hash value and potentially managing collision buckets, making them slightly more memory-intensive than raw lists. Furthermore, calculating the hash function takes time, which is usually negligible (O(1)), but it is part of the constant factor hidden within the asymptotic notation.
๐ŸŒ
technetexperts.com
technetexperts.com โ€บ home โ€บ optimizing array intersection to o(n+m) complexity
Optimizing Array Intersection to O(n+m) Complexity
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python set intersection()
Python Set intersection() โ€“ Be on the Right Side of Change
April 30, 2021 - The runtime complexity of the set.intersection() method on a set with n elements and a set argument with m elements is O(min(n, m)) because you need to check for the smaller set whether each of its elements is a member of the larger set.
๐ŸŒ
GoLinuxCloud
golinuxcloud.com โ€บ home โ€บ programming โ€บ master python set intersection()
Master Python set intersection() [Practical Examples]
November 28, 2023 - Understanding the performance implications of using set operations like intersection can be crucial when you're working with large data sets. You can use Python's timeit library to measure the time taken for set operations.
Find elsewhere
๐ŸŒ
Eugene-eeo
eugene-eeo.github.io โ€บ blog โ€บ intersection-algorithms.html
Intersection Algorithms
However: Space complexity is essentially O(1) Time complexity is higher, at worse O(max(n,m)) due to the additional deletes. def intersection(A, B): b = len(B) - 1 a = len(A) - 1 # Find intersections, and set a to be the index # where the algorithm should search from for i in range(b, -1, -1): ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ internal-working-of-set-in-python
Internal working of Set in Python - GeeksforGeeks
July 11, 2025 - The time complexity for this operation is O(len(s1)), where s1 is the set from which elements are being subtracted. ... The symmetric difference between two sets is the set of elements that are in either of the sets but not in both.
๐ŸŒ
TechNetExperts
technetexperts.com โ€บ home โ€บ optimizing array intersection to o(n+m) complexity
Optimizing Array Intersection to O(n+m) Complexity
February 20, 2026 - Because Python sets support efficient algebraic operations, the intersection can be calculated directly. The total time complexity of this approach is dominated by the initial set creation, resulting in an overall complexity of O(N + M).
๐ŸŒ
CSDN
devpress.csdn.net โ€บ python โ€บ 6304635dc67703293080c375.html
Time complexity of python "set.intersection" for n sets_python_Mangs-Python
August 23, 2022 - The python wiki on time complexity lists a single intersection as O(min(len(s), len(t)) where s and t are the sizes of the sets and t is a set.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ set-intersection-python
Python Set Intersection with Examples and Codes
December 9, 2023 - Learn how to find the Intersection of sets in python using the intersection function and intersection operator with examples.
๐ŸŒ
Answers
math.answers.com โ€บ computer-science โ€บ What-is-the-time-complexity-of-finding-the-intersection-of-two-sets-in-python-using-the-set-intersection-operation
What is the time complexity of finding the intersection of two sets in Python using the set intersection operation? - Answers
February 8, 2025 - The time complexity of finding the intersection of two sets in Python using the set intersection operation is O(min(len(set1), len(set2)), where set1 and set2 are the two sets being intersected.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ hashing-dictionaries-and-sets-in-python โ€บ lessons โ€บ mastering-python-sets-intersection-non-repeating-elements-and-unique-elements
Mastering Python Sets: Intersection, Non-Repeating ...
Next, we return a list with the elements in the seen set but not in the repeated set. Consequently, our final solution would look as follows: This approach results again in a time complexity of ... O(n)O(n) due to the constant time operations provided by the Python set.
๐ŸŒ
Betterdatascience
betterdatascience.com โ€บ python-set-intersection
Python Set Intersection - The Ultimate Guide for Beginners | Better Data Science
July 2, 2022 - In the last week’s article, youโ€™ve learned what Python set difference() is all about. Now weโ€™ll explore another commonly used set function. Python set intersection allows you to find common elements between two or more sets.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-fastest-way-to-perform-a-Set-Intersection-in-big-Oh
What is the fastest way to perform a Set Intersection in big-Oh? - Quora
Answer: Depends a lot on what is the data structure used to implement the sets. If you are using sorted lists to represent the sets, you can simply walk through the two lists popping the larger element off the head, and recording a common element ...
๐ŸŒ
Medium
medium.com โ€บ @developerstoday99 โ€บ python-set-data-structure-methods-use-time-and-space-complexity-366b8c408345
Python Set Data Structure: Methods, Use, Time, and Space Complexity | by Developers Today | Medium
April 22, 2023 - Finally, we convert the resulting set back to a list using the list function and return it. By using sets, we can solve this problem efficiently in O(n) time complexity, where n is the total number of elements in both lists.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ intersection-function-python
Intersection() function Python - GeeksforGeeks
August 9, 2022 - Python Set clear() Method Syntax: Syntax: set.clear() parameters: The clear() method doesn't take any parameters. ร‚ Return: None Time complexity : The time complexity of set.clear() function on a set with n element is O(n) .