Professional Documents
Culture Documents
Set Operations
We represent a set by the Set union:
sorted sequence of its aIsLess(a, S)
elements
Sets By specializing the auxliliary
S.insertFirst(a)
bIsLess(b, S)
methods he generic merge S.insertLast(b)
algorithm can be used to bothAreEqual(a, b, S)
perform basic set S. insertLast(a)
operations:
union
Set intersection:
aIsLess(a, S)
intersection
{ do nothing }
subtraction
bIsLess(b, S)
The running time of an
{ do nothing }
operation on sets A and B
should be at most O(nA + nB) bothAreEqual(a, b, S)
S. insertLast(a)
Sets 1 Sets 2
Sets 3 Sets 4
Sets 5