Time complexity of python "set.intersection" for n sets -
i want know complexity of set.intersection of python. looked in documentations , online wikis python, did not find time complexity of method multiple sets.
the python wiki on time complexity lists single intersection o(min(len(s), len(t)) s , t the sizes of sets , t set. (in english: time bounded , linear in size of smaller set.)
note: based on comments below, wiki entry had been wrong if argument passed not set. i've corrected wiki entry.
if have n sets (sets, not iterables), you'll n-1 intersections , time can (n-1)o(len(s)) s set smallest size.
note intersection result may smaller, although o worst case, in practice, time better this.
however, looking @ specific code idea of taking min() applies single pair of sets , doesn't extend multiple sets. in case, have pessimistic , take s set largest size.
Comments
Post a Comment