ut any duplicates. It E48. A set consists of entries that are in no particular o
ID: 3593090 • Letter: U
Question
ut any duplicates. It E48. A set consists of entries that are in no particular order, without a» which this operation is invoked mod Union with another set: the set on which this operation is invoked contain the members that are either in itself or in the given set. i modified Intersection with another set: the set on which this operation is modified to contain the members that are common to itself and the supports (apart from others) three fundamental operations: is modified to on is invoked is . Difference with another set: the set on which this operation is invo modif to contain only entries that are not also members of the given set. (a) Can a set be implemented using an unordered list? (b) If so, describe how each of the above set operations can be impl enum erate, an of the unordered list operations append, remove,Explanation / Answer
Question A.
Yes we can implement a Set using the help of unordered list. Please refer below Set operations which were implemented using various unordered list operations.
Question B.
Set Operation UNION: Here we will perform this operation on a List by passing another List as parameter.
Algorithm:
Pre Alogorithm: Enumerate the List B using the list operation enumerate. This enumaration will allow us to iterate through each element in the List B.
1. For each Element in List B
2. Compare List A with element in List B using list operation contains (List A.contains(element of List B))
3. If List A contains List B element then do nothing, else add List B element to List A using list operation append
After implementing above 3 steps for each element in List B, finally we will have all elements either in List A or in List B or Both, in List A. This will give us the SET operation UNION Set A on Set B.
Set Operation INTERSECTION: Here we will perform this operation on a List by passing another List as parameter.
Algorithm:
Pre Alogorithm: Enumerate the List A using the list operation enumerate. This enumaration will allow us to iterate through each element in the List A.
1. For each Element in List A
2. Compare element of List A with List B using list operation contains (List B.contains(element of List A))
3. If List B contains List A element then do nothing, else remove List A element from List A using list operation remove
After implementing above 3 steps for each element in List A, finally we will have all elements that are common to List A and List B, in List A. This will give us the SET operation INTERSECTION Set A ON Set B.
Set Operation DIFFERENCE: Here we will perform this operation on a List by passing another List as parameter.
Algorithm:
Pre Alogorithm: Enumerate the List A using the list operation enumerate. This enumaration will allow us to iterate through each element in the List A.
1. For each Element in List A
2. Compare element of List A with List B using list operation contains (List B.contains(element of List A))
3. If List B does not contains List A element then do nothing, else remove List A element from List A using list operation remove
After implementing above 3 steps for each element in List A, finally we will have all elements that are in List A but not in List B, in List A. This will give us the SET operation INTERSECTION Set A ON Set B.
Kindly Let me know if you need more details
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.