we can improve upon the asymptotic performance with simple observation once inside the body of the loop over bif selected elements and do not match each otherit is waste of time to iterate through all values of looking for matching triple an improved solution to this problemtaking advantage of this observationis presented in code fragment def disjoint (abc) """return true if there is no element common to all three lists "" for in for in if =bonly check if we found match from and for in if = (and thus = = return false we found common value return true if we reach thissets are disjoint code fragment algorithm disjoint for testing three-way set disjointness in the improved versionit is not simply that we save time if we get lucky we claim that the worst-case running time for disjoint is ( there are quadratically many pairs (abto consider howeverif and are each sets of distinct elementsthere can be at most (nsuch pairs with equal to thereforethe innermost loopover cexecutes at most times to account for the overall running timewe examine the time spent executing each line of code the management of the for loop over requires (ntime the management of the for loop over accounts for total of ( timesince that loop is executed different times the test = is evaluated ( times the rest of the time spent depends upon how many matching (abpairs exist as we have notedthere are at most such pairsand so the management of the loop over cand the commands within the body of that loopuse at most ( time by our standard application of proposition the total time spent is ( element uniqueness problem that is closely related to the three-way set disjointness problem is the element uniqueness problem in the formerwe are given three collections and we presumed that there were no duplicates within single collection in the element uniqueness problemwe are given single sequence with elements and asked whether all elements of that collection are distinct from each other our first solution to this problem uses straightforward iterative algorithm the unique functiongiven in code fragment solves the element uniqueness problem by looping through all distinct pairs of indices kchecking if any of