W1525 Containment

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Nuclear containment

Prerequisites[edit]

Research[edit]

Background[edit]

Set Basics[edit]

By the 1930's, through the work of Godel, Church, Turing and others, it was realized that Set Theory relied on an even more basic concept, that of computability. Computer Science continues to be inspired by Set Theory and understanding Set Theory should facilitate your ability to think abstractly. It is, by its nature, independent of yet critical for programming.

A set is an unordered collection of objects. The objects are referred to as elements or members of the set.

Symbols Definition
The empty set
Another way of symbolizing the empty set
The set containing the elements
is a member of the set
is NOT a member of the set
The set of natural numbers
0 The set of natural numbers with zero
The set of integers (negative, zero, and positive)
The set of real numbers
The set X is a subset of the set Y
The set X is NOT a subset of the set Y

A set is termed a subset of set iff every element of is an element of . Formally:

Two sets and are equal iff every element of is an element of and vice versa. Formally:

Boolean Algebra of Sets[edit]

Assume set . The following operations are defined:

Symbols Name Definition
Union
Intersection
Complement


Set Union[edit]

The union of two sets and , both subsets of the set , i.e.


Set Intersection[edit]

The intersection of sets and , both subsets of the set , i.e.


Set Complement[edit]

Consider the set , a subset of the set
Then is the compliment of


Sets in Swift[edit]

Sets are useful when we want to check efficiently to determine whether an element is a member of a set AND the order of the elements in the collection doesn't matter.

The most useful methods are:

Method Purpose
contains Returns true iff the element is contained in the set
== Returns true iff both sets contain the same elements
isSubset Returns true if the set contains ALL of the elements of another
union Returns a new set which contains ALL of the elements of the original set and another
intersection Returns a new set with only the elements that are in common to the original set and another
Hint.pngHelpful Hint
Set operations can be used with another set, an array, or any other sequence type. Likewise, sequence and collection operations can be used on sets.

Experiment[edit]

Getting Started[edit]

Continue from the previous project; we'll be editing all of our files there. Enter into the Sources directory of the project.

john-williams@codermerlin: cd ~/Experiences/W1521/Sources/ScenesShell/

Key Concepts[edit]

Exercises[edit]

References[edit]