Docsity

Sets: Lecture 22 - Set Definitions and Implementations, Slides of Data Structures and Algorithms

Partial preview of the text

Download Sets: Lecture 22 - Set Definitions and Implementations and more Slides Data Structures and Algorithms in PDF only on Docsity!

Chapter 9 Sets

Lecture 22

ADT Set Definitions

Base type: The type of the items in the set

Cardinality : The number of items in a set

Cardinality of the base type : The number of items in the base type

Union of two sets: A set made up of all the items in either sets

Intersection of two sets : A set made up of all the items in both sets

Difference of two sets : A set made up of all the items in the first set that are not in the second set

Implementing Sets

Explicit implementation (Bit vector)

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).

Space is proportional to the cardinality of the

base type.

Algorithms use Boolean operations.

Implementing Sets (cont.)

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.

Space is proportional to the cardinality of the

set instance.

Algorithms use ADT List operations.