algorithm analysis def unique ( ) """return true if there are no duplicate elements in sequence "" for in range(len( )) for in range( + len( )) if [ = [ ] return false found duplicate pair return true if we reach thiselements were unique code fragment algorithm unique for testing element uniqueness those pairs refer to elements that are equivalent to each other it does this using two nested for loopssuch that the first iteration of the outer loop causes iterations of the inner loopthe second iteration of the outer loop causes iterations of the inner loopand so on thusthe worst-case running time of this function is proportional to ( ( which we recognize as the familiar ( summation from proposition using sorting as problem-solving tool an even better algorithm for the element uniqueness problem is based on using sorting as problem-solving tool in this caseby sorting the sequence of elementswe are guaranteed that any duplicate elements will be placed next to each other thusto determine if there are any duplicatesall we need to do is perform single pass over the sorted sequencelooking for consecutive duplicates python implementation of this algorithm is as follows def unique ( ) """return true if there are no duplicate elements in sequence "" temp sorted(screate sorted copy of for in range( len(temp)) if [ - = [ ] return false found duplicate pair return true if we reach thiselements were unique code fragment algorithm unique for testing element uniqueness the built-in functionsortedas described in section produces copy of the original list with elements in sorted order it guarantees worst-case running time of ( log )see for discussion of common sorting algorithms once the data is sortedthe subsequent loop runs in (ntimeand so the entire unique algorithm runs in ( log ntime