Download presentation
Presentation is loading. Please wait.
1
Sets CS3240, L. grewe
2
Goals Describe a set at the logical level and implement a set both explicitly and implicitly
3
Sets Set An unordered collection of distinct values (items or components), chosen from the possible values of a single data type, called the component or base type Base type The type of the items in the set Cardinality The number of items in a set Subset A set contained within another set
4
Sets Universal set A set that contains all the values of the base type
Empty set A set with no members Set union A set made up of all the items in either sets Set intersection A set made up of all the items in both sets Set difference A set made up of all the items in the first set that are not in the second set
5
Sets Given SetA = {X, Y, Z, A, B} SetB = {A, C, W, Z}
What is SetA union SetB? What is SetA intersection SetB? What is SetA - SetB (difference)? Give a subset of SetA Give a proper subset of SetB
6
Sets Beware At the Logical Level sets can not contain duplicates
Inserting a duplicate item into a set does not change the set Sets are not ordered This does not mean that we cannot implement a set using an ordered structure with duplicates
7
Sets Explicit implementation
Each item in the base type has a representation in each instance of a set; the representation is either true (item is in the set) or false (item is not in the set) Bit Vector An array of Boolean flags, with each item in the base type mapped to a specific flag (index) Algorithms use Boolean operations To what is space for each set instance proportional?
8
Sets If sets A and B are represented as bit vectors, what Boolean operation would implement set union? Set intersection? Set difference?
9
Sets Implicit implementation (List)
The items in an instance of a set are on a list that represents the set; those items that are not on the list are not in the set Algorithms use ADT List operations To what is space for each set instance proportional?
10
Sets If sets A and B are represented as lists, what list operations would implement set union? Set intersection? Set difference? Which list implementation would be more efficient?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.