2. Implementations of Set Operations. Consider the implementation of a mathematical set¹ that supports the functions Ins
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
2. Implementations of Set Operations. Consider the implementation of a mathematical set¹ that supports the functions Ins
Union creates a new UnorderedSet that contains the union of two sets: S1 UnorderedSet ({1, 2, 3, 4}) 5, 7} S2 = UnorderedSet({3, S3 Union (S1, S2) #Now S3 is {1, 2, 3, 4, 5, 7} and S1 and S2 are unchanged Union InPlace adds the elements of another set to the current set: S1. UnionInPlace (S2) # Now S1 is {1, 2, 3, 4, 5, 7 and S2 is unchanged (a) For a sorted array implementation, write pseudocode for the above four functions. State the asymptotic complexity for each function and give a brief justification. (b) Repeat the above for an unsorted linked-list implementation of each of the four functions.