User Tools

Site Tools


notes:discrete:fall2023:projects:set0

This is an old revision of the document!


SET0

Terms

member

Venn Diagram

a Venn Diagram is a diagram style that shows the logical relation between sets. This diagram is composed of circles with the values of each set inside their own circles. This allows a value from a set to be present in more than one circle. For example, we can have one circle containing animals that can fly, and one circle containing animals with two legs. Animals with both, two legs, and can fly, will be presented in the overlapping section of the circles while animals with only one of those qualities will be present in only one circle.

set

A set is a group of unique objects, typically ordered in some way or another. Sets are typically used to test membership of a given value rather than retrieving a specific element.

universe

A Universe or a Universal set has all components of all sets within it. It is typically written as U. An example: if A{1,2,3} and B{a,b,c} then U{1,2,3,a,b,c}. If you think of a Venn Diagram then a Universal set is the whole Diagram.

Set Logic

union

The union of sets is an operation that combines two or more sets to create a new set that contains all the unique elements from the input sets. In other words, the union of sets A and B, denoted by A ∪ B, is a union of sets A and B includes all elements that are present in either A or B, without duplicating any elements. If an element appears in both sets A and B, it is included in the union only once. You can extend this concept to the union of more than two sets. The union of three or more sets, such as A ∪ B ∪ C, includes all elements that are present in any of the three sets. The union operation is commutative, meaning that the order of the sets does not matter; A ∪ B is the same as B ∪ A.

intersection

The intersection of Sets is defined as the set of common elements of all the sets. This operation can be thought of as being equivalent to the logical AND operator. If set A = { 1, 3, 5, 8, 9 } and set B = { 2, 3, 5, 7, 9 }, the intersection of A and B, written as A ∩ B = { 3, 5, 9 }

complement

The complement of a set is the difference of a set and the Universal set. Mathematically is can be seen as U{1,2,3,a} - A{2,3} = A'{1,a}. In a Venn diagram if the Universal set is the whole picture then the complement is the space that is not in the Venn Diagram.

difference

disjoint / mutually exclusive

What is disjoint

Disjoint in relation to set logic is when you are given two sets that do not share anything in common at all. Here is a simple example. you have a set A that consists of elements 1,2,3,4 and a set B that consists of elements 5,6,7,8. The two sets do not have any of the same elements thus the two sets are disjoint.

Here is also an example of two sets that are not disjoint. you are given set A which consists of 1,2,3,4 and set B which consists of 3,4,5,6. Because the two sets contain some of the same elements the sets are not disjoint.

How to show Disjoint using Venn Diagram

I found that displaying an example of disjoint sets was the easiest out of all the set logic. Instead of having two circles overlapping, you have two circles separated there for the sets are disjoint (not connected/share similar elements).

Simple Function for disjoint

When you are creating your disjoint function use the following as inspiration.

int disjointSets(int *set1, int size1, int *set2, int size2)
{
    // Iterate through set 1
    for (int i = 0; i < size1; i++)
    {
        // Check if the current element of set 1 is in set 2
        for (int j = 0; j < size2; j++)
        {
            if (set1[i] == set2[j])
            {
                return 0; // Not disjoint because the two sets have a common element
            }
        }
    }
    return 1; // Disjoint because the two sets do not have a common element
}
notes/discrete/fall2023/projects/set0.1699459267.txt.gz · Last modified: 2023/11/08 16:01 by walley