This preview shows page 1. Sign up to view the full content.
Unformatted text preview: For example: ± For intersection : only copy elements that are duplicated in both list ± For union : copy every element from both lists except for the duplicates All methods run in linear time. Sets 5 Set Operations We represent a set by the sorted sequence of its elements By specializing the auxliliary methods he generic merge algorithm can be used to perform basic set operations: ± union ± intersection ± subtraction The running time of an operation on sets A and B should be at most O ( n A + n B ) Set union: ± aIsLess ( a, S ) S.insertFirst ( a ) ± bIsLess ( b, S ) S.insertLast ( b ) ± bothAreEqual ( a, b, S ) S. insertLast ( a ) Set intersection: ± aIsLess ( a, S ) { do nothing } ± bIsLess ( b, S ) { do nothing } ± bothAreEqual ( a, b, S ) S. insertLast ( a )...
View
Full
Document
This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue UniversityWest Lafayette.
 Fall '08
 Staff
 Data Structures, Sort

Click to edit the document details