Vous êtes sur la page 1sur 3

Department of Computer Engineering, KBTCOE

Experiment No: 01 Date:

1.1 Aim:
In Second year Computer Engineering class of M students, set A of students play cricket and set B of
students play badminton. Write C/C++ program to find and display-

a. Set of students who play either cricket or badminton or both


b. Set of students who play both cricket and badminton
c. Set of students who play only cricket
d. Set of students who play only badminton
e. Number of students who play neither cricket nor badminton
(Note- While realizing the set duplicate entries are to avoided)

.1.2 Objectives: To implement set operations using arrays

1.3 Software used (if applicable) / Programming Languages Used: Ubuntu 14.04 Operating
system, g++

1.4. Theory:
A set is a collection of objects that have something in common or follow a rule. The objects in
the set are called its elements. Set notation uses curly braces, with elements separated by
commas. So the set of outwear for a girl would be listed as follows:

A = {coat, hat, scarf, gloves, boots}, where A is the name of the set, and the braces indicate that
the objects written between them belong to the set.

Every object in a set is unique: The same object cannot be included in the set more than
once.
The following conventions are used with sets:

Capital letters are used to denote sets.


Lowercase letters are used to denote elements of sets.
Curly braces { } denote a list of elements in a set.

Following are the examples of sets:

1. A = {coat, hat, scarf, gloves, boots}


2. P = {thumb, index, middle, ring, little}
3. Q = {2, 4, 6, 8}
4. X = {red, blue, yellow}

Universal Set
It's a set that contains everything.. Everything that is relevant to the concept.
If the set included integers. The universal set for that is all the integers. In fact, in Number Theory,
the universal set is the set of integers.
But in Calculus (also known as real analysis), the universal set is almost always the real numbers.
And in complex analysis, the universal set is the complex numbers.
Page 1 of 3
Department of Computer Engineering, KBTCOE
Also, when we say an element a is in a set A, we use the symbol to show it.
And if something is not in a set use .

Example: Set A is {1,2,3}. We can see that 1 A, but 5 A

Equality
Two sets are equal if they have precisely the same members. Example: Are A and B equal
where:
A is the set whose members are the first four positive whole numbers
B = {4, 2, 1, 3}
Let's check. They both contain 1. They both contain 2. And 3, And 4. And we have checked
every element of both sets, so: Yes, they are equal!
And the equals sign (=) is used to show equality, so we write:
A=B

Subsets
When we define a set, if we take pieces of that set, we can form what is called a subset.
Example: the set {1, 2, 3, 4, 5}
A subset of this is {1, 2, 3}. Another subset is {3, 4} or even another is {1}, etc.
But {1, 6} is not a subset, since it has an element (6) which is not in the parent set.
In general:
A is a subset of B if and only if every element of A is in B.

Proper Subsets

A is a proper subset of B if and only if every element in A is also in B, and there exists at
least one element in B that is not in A.

Example:
{1, 2, 3} is a proper subset of {1, 2, 3, 4} because the element 4 is not in the first set.
Notice that if A is a proper subset of B, then it is also a subset of B.
When we say that A is a subset of B, we write A B.
Or we can say that A is not a subset of B by A B ("A is not a subset of B")
When we talk about proper subsets, we take out the line underneath and so it becomes A B
or if we want to say the opposite, A B.

Empty (or Null) Set


It is a set with no elements.
This is known as the Empty Set (or Null Set).There aren't any elements in it.
It is represented by
Or by {} (a set with no elements)

Empty Set and Subsets

The empty set is a subset of every set, including the empty set itself.

Order
No, not the order of the elements. In sets it does not matter what order the elements are in.
Example: {1,2,3,4} is the same set as {3,1,4,2}
When we say "order" in sets we mean the size of the set.
Just as there are finite and infinite sets, each has finite and infinite order.
For finite sets the order is the number of elements.

Page 2 of 3
Department of Computer Engineering, KBTCOE
Example, {10, 20, 30, 40} has an order of 4.
For infinite sets, the order is infinite.

Basic operations on Sets

Set theory includes binary operations on sets like:

Union of the sets A and B, denoted AB, is the set of all objects that are a member of A, or B,
or both. The union of {1, 2, 3} and {2, 3, 4} is the set {1, 2, 3, 4} .
Intersection of the sets A and B, denoted A B, is the set of all objects that are members of
both A and B. The intersection of {1, 2, 3} and {2, 3, 4} is the set {2, 3} .
Set difference of U and A, denoted U \ A, is the set of all members of U that are not members
of A. The set difference {1, 2, 3} \ {2, 3, 4} is {1} , while, conversely, the set difference {2,
3, 4} \ {1, 2, 3} is {4} . When A is a subset of U, the set difference U \ A is also called the
complement of A in U. In this case, if the choice of U is clear from the context, the notation
Ac is sometimes used instead of U \ A, particularly if U is a universal set as in the study of
Venn diagrams.
Symmetric difference of sets A and B, denoted AB or AB, is the set of all objects that are
a member of exactly one of A and B (elements which are in one of the sets, but not in both).
For instance, for the sets {1, 2, 3} and {2, 3, 4} , the symmetric difference set is {1, 4} . It is
the set difference of the union and the intersection, (AB) \ (A B) or (A \ B) (B \ A).
Cartesian product of A and B, denoted A B, is the set whose members are all possible
ordered pairs (a, b) where a is a member of A and b is a member of B. The cartesian product
of {1, 2} and {red, white} is {(1, red), (1, white), (2, red), (2, white)}.
Power set of a set A is the set whose members are all possible subsets of A. For example, the
power set of {1, 2} is { {}, {1}, {2}, {1, 2} } .

1.5. Algorithm:

1. Read the sets of students playing cricket and badminton.


2. Apply the basic set operations and find the set of students playing both games .i.e A B.
3. Compute the set AB that represents students playing either cricket or badminton or both.
4. Find the set AB- B that represents students playing only cricket.
5. Find the set AB- A that represents students playing only badminton.
6. Find the set U- AB that represents students playing neither cricket nor badminton.
7. Display the resultant sets.

Signature of Staff with Date

1.6 Questions

1 State all the laws of set theory.


2 Define: Cardinality of set, Infinite set and countable infinite set.
3 Prove De- Morgans laws using Venn diagram notations.

Page 3 of 3

Vous aimerez peut-être aussi