Discrete Mathematics
Discrete Mathematics
UNIVERSITY
Discrete Mathematics
(MR23-1BS0801)
UNIT-I: Binary Relations on Sets
Syllabus
Binary Relations, Equivalence Relations, Partial Order Sets, Total Order Sets, Lattices,
Hasse Diagrams, Functions, Binary and n-ary Operations.
--
Sets
Definition: “A set is a well-defined collection of objects.” These objects are called elements
or members of the set.
So, we can say that it is the collection of all such type of elements or objects which satisfy
some rule and it is possible to say whether a particular object belongs to the collection or not.
We write a A to denote that “ a is an element of the set A”. Similarly, a A is used to
denote that “ a is not an element of the set A”. It is common for sets to be denoted by using
uppercase letters. Lowercase letters are usually used to denote elements of sets.
Examples: 1. The set V of all vowels in the English alphabet can be written as
V {a, e, i, o, u} .
2. The set O of odd positive integers less than 10 can be expressed by O {1,3,5,7,9} .
3. Although sets are usually used to group together elements with common properties, there is
nothing that prevents a set from having seemingly unrelated elements. For instance,
{a, 2, Fred, New Jersey} is the set containing the four elements a, 2, Fred, and New Jersey.
4. The set of positive integers less than 100 can be denoted by {1, 2,3, . . . ,99}.
Remark: Sets can have other sets as members. For example, the set {N, Z, Q, R} is a set
containing four elements, each of which is a set. The four elements of this set are N, the set of
natural numbers; Z, the set of integers; Q, the set of rational numbers; and R, the set of real
numbers.
Remark: Note that the concept of a datatype, or type, in computer science is built upon the
concept of a set. In particular, a datatype or type is the name of a set, together with a set of
operations that can be performed on objects from that set. For example, boolean is the name
of the set {0,1} together with operators on one or more elements of this set, such as AND,
OR, and NOT.
Problem: Describe the set containing all the nonnegative integers less than or equal to 5.
Solution: Let A denote the set. Then the set A can be described in the following ways:
--
1. A = {x | x is a nonnegative integer less than or equal to 5}.
2. A = {0,1,2,3,4,5}.
1 for x 0,1, 2,3, 4,5
3. A x
0 otherwise
4. A = xi 1 xi 1, i 0,1, 2,3, 4, where x0 0 .
Remark: Sometimes in roster method, a set is described without listing all its members.
Some members of the set are listed, and then ellipses (. . .) are used when the general pattern
of the elements is obvious.
Subset: Let A and B be two sets. Then A is said to be a subset of B if every element of A is an
element of B.
If A is a subset of B, we say A is contained in B. Symbolically, we write A B .
Equal Sets: Two sets A and B are equal iff A B and B A . We write A B .
Result: To show that two sets A and B are equal, we must show that each element of A is also
an element of B, and conversely.
Null Set or Empty Set: A set containing no elements is called the empty set or null set,
denoted by .
For example, given the universal set U of all positive numbers, the set of all positive numbers
x in U satisfying the equation x 1 0 is an empty set since there are no positive numbers
which can satisfy this equation.
Note: It is important to note that the sets and are very different sets. The former has
no elements, whereas the latter has the unique element .
--
Operations on Sets
There are several operations on set. A few important ones are discussed in this section.
Consider U as the universal set and now we define the following operations.
Relative Complement: If A and B are sets, the relative complement of A with respect to B is
given as B A x : x B and x A .
Disjoint Sets: Two sets A and B are said to be disjoint if they do not have a member in
common.
Mathematically, A B .
--
Distributive Laws: Let A, B and C are three sets. Then,
C A B C A C B ,
C A B C A C B .
Power Set: Let A be a given set. The power set of A, denoted by P(A), is the family of sets
such that X A iff X P A .
Symbolically,
P A X : X A .
Example: Let A a, b, c . Then the power set of A is
P A , a , b , c , a, b , b, c , c, a , a, b, c .
Venn Diagram
It is often helpful to use Venn diagram [after JohnVenn (1834-1883)], to visualize the various
properties of the set operations. The main points of Venn Diagram are:
The universal set is represented by a large rectangular area.
Subsets within this universe are represented by circular areas.
--
De Morgan’s Laws: Let A and B be two sets. Then,
A B A B
A B A B
Note: The proof of the above laws can be given with the help of Venn diagram.
Problem: Let U 1, 2,3, 4,5 , A 1,5 , B 1, 2,3, 4 . Find the following sets.
(a) A B
(b) A B
Solution: (a) A B = 1,5 U B
= 1,5 5
= 5
(b) A B = U A U B
= 2,3, 4 5
= 2,3, 4,5
Multiset
In mathematics, a multiset (or bag, or mset) is a modification of the concept of a set that,
unlike a set, allows for multiple instances for each of its elements.
The number of instances given for each element is called the multiplicity of that
element in the multiset.
These objects are all different, when viewed as multisets, although they are the same
set, since they all consist of the same elements. As with sets, and in contrast to tuples, order
--
does not matter in discriminating multisets, so {a, a, b} and {a, b, a} denote the same
multiset.
Note: To distinguish between sets and multisets, a notation that incorporates square brackets
is sometimes used: the multiset {a, a, b} can be denoted as [a, a, b].
Example: One of the simplest and most natural examples is the multiset of prime factors of a
natural number n. Here the underlying set of elements is the set of prime factors of n. We
know that 120 = 23 31 51 which gives the multiset {2, 2, 2, 3, 5}.
Relations
Ordered Pair: In ordered pair, each set is specified by two objects in a prescribed order. The
ordered pair of a and b, with first coordinate a and second coordinate b, is the set a, b .
Cartesian Product: Let A and B are two sets. The Cartesian product of A and B is defined as
A B a, b : a A and b B .
Note: From the definition of the Cartesian product we have seen that any element a, b in a
Cartesian product A B is just an ordered pair.
--
Binary Relation: A binary relation R from A to B is a subset of Cartesian product A B .
Example: Let all the points inside a unit circle whose centre is at the origin. Then the set
R x, y : x and y are real numbers and x 2 y 2 1
is a relation on the set of real numbers.
Note: 1- Here, dom R A and ran R B . Moreover, the domain of R is the set of first
coordinates in R and the range of R is the set of second coordinates in R.
Equivalence Relation
Example: Let N 1, 2,3, be the set of natural numbers. Define a relation R in N as
follows:
R x, y ; x, y N and x y is even .
--
R is an equivalence relation in N because the first two conditions are clearly satisfied and to
prove the third condition, if x y and y z are divisible by 2, then x y y z is
divisible by 2. Therefore, x z is divisible by 2. Hence Proved.
Note: In this equivalence relation all the odd numbers are equivalent and so are all the even
numbers.
Congruence modulo ‘m’: Let ‘m’ be any positive integer then the relation congruence
modulo ‘m’ mod m is defined by x y mod m iff x y a.m for some integer a.
Theorem: For any positive integer m, the relation mod m is an equivalence relation on
the integers, and partitions the integers into „m‟ distinct equivalence classes: [0], [1],…,[m-1].
1. Reflexivity: a a m.0
a a mod m
aRa .
--
bRa .
x mq r
where q and r are integers and 0 r m .
So, each equivalence class for this relation is one of the classes [0],[1],…,[m-1].
Ordering Relations
Order Theory: It studies various kinds of binary relations that capture the intuitive notion of
ordering expressed usually using phrases "less than" or "precedes".
Note: The relation on the set of real numbers is the prototype of a partial order, so it is
common to write to represent an arbitrary partial order on A.
1. Reflexivity i.e. a A, a a
--
2. Antisymmetry i.e. a,b∈ A, if a b and b a then a=b
3. Transitivity i.e. a,b,c∈ A, if a b and b c then a c
Comparable: Two elements a and b in a set A are said to be comparable under if either
A b or b a; otherwise, they are incomparable.
Totally Ordered Set: If every pair of elements of a set A are comparable, then we say that
[A; ] is totally ordered or that A is a totally ordered set or a chain.
Examples: 1. If Z is the set of integers and is the usual ordering on Z, then [Z; ]is
partially ordered and totally ordered.
Lattices
.
A lattice is a partially ordered set (L, ≤) in which every pair of elements a, b ∈ L has a greatest
lower bound and a least upper bound.
Example: Let Z+ denote the set of all positive integers and let R denote the relation ‘division‘ in
Z+, such that for any two elements a, b ∈ Z+, aRb, if a divides b. Then (Z+, R) is a lattice in
which the join of a and b is the least common multiple of a and b, i.e.
a ∨ b = a ⊕ b = LCM of a and b,
and the meet of a and b, i.e. a ∗ b is the greatest common divisor (GCD) of a and b i.e.,
a ∧ b = a ∗ b = GCD of a and b.
We can also write a+b = a∨b = a⊕b=LCM of a and b and a.b = a∧b = a∗b=GCD of a and b.
Example: Let n be a positive integer and Sn be the set of all divisors of n If n = 30, S30 = {1, 2,
3, 5, 6, 10, 15, 30}. Let R denote the relation division as defined in Example 1. Then (S30, R) is
a Lattice see Fig:
--
Example: Let A be any set and P (A) be its power set. The poset (P (A), ⊆) is a lattice in which
the meet and join are the same as the operations ∩ and ∪ on sets respectively.
S = {a}, P (A) = {ϕ, {a}}
The above properties (L1) to (L4) can be proved easily by using definitions of meet and
join. We can apply the principle of duality and obtain (L1)′ to (L4)′.
Complemented lattice:
A complemented lattice is a bounded lattice (with least element 0 and greatest element 1), in
which every element a has a complement, i.e. an element b satisfying a ∨ b = 1 and a ∧ b = 0.
Complements need not be unique.
--
Example: Lattices shown in Fig (a), (b) and (c) are complemented lattices.
Sol.
For the lattice (a) GLB(a, b) = 0 and LUB(x, y) = 1. So, the complement a is b and vise versa.
Hence, a complement lattice.
For the lattice (b) GLB(a, b) = 0 and GLB(c, b) = 0 and LUB(a, b) = 1 and LUB(c, b) = 1; so
both a and c are complement of b.
Hence, a complement lattice.
In the lattice (c) GLB(a, c) = 0 and LUB(a, c) = 1; GLB(a, b) = 0 and LUB(a, b) = 1. So,
complement of a are b and c.
Similarly complement of c are a and b also a and c are complement of b.
Hence lattice is a complement lattice.
Hasse Diagrams
A partial order ≤ on a set P can be represented by means of a diagram known as Hasse diagram
of (P, ≤). In such a diagram,
(i). Each element is represented by a small circle or dot.
(ii). The circle for x ∈ P is drawn below the circle for y ∈ P if x < y, and a line is drawn
between x and y if y covers x.
(iii). If x < y but y does not cover x, then x and y are not connected directly by a single line.
Note: For totally ordered set (P, ≤), the Hasse diagram consists of circles one below the other.
The poset is called a chain.
Example: Let P = {1, 2, 3, 4, 5} and ≤ be the relation “less than or equal to” then the Hasse
diagram is:
Sol: R= {(1, 1), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 3), (3, 4), (3, 5), (4, 4), (5.5)}.
Hasse diagram for MR is
Example: A partial order R on the set A = {1, 2, 3, 4} is represented by the following digraph.
Draw the Hasse diagram for R.
--
Example: Draw the Hasse diagram for the partial ordering ⊆ on the power set P (S) where
S = {a,b, c}.
Note:
(i). The minimal and maximal members of a partially ordered set need not unique.
(ii). Maximal and minimal elements are easily calculated from the Hasse diagram.
They are the 'top' and 'bottom' elements in the diagram.
Example:
In the Hasse diagram, there are two maximal elements and two minimal elements.
The elements 3, 5 are maximal and the elements 1 and 6 are minimal.
--
Upper and Lower Bounds: Let (P, ≤) be a partially ordered set and let A ⊆ P . Any element
x ∈ P is called an upper bound for A if for all a ∈ A, a ≤ x. Similarly, any element x ∈ P is called
a lower bound for A if for all a ∈ A, x ≤ a.
Example: Find the great lower bound and the least upper bound of {b, d, g}, if they exist in the
poset shown in fig:
Solution: The upper bounds of {b, d, g} are g and h. Since g < h, g is the least upper bound. The
lower bounds of {b, d, g} are a and b. Since a < b, b is the greatest lower bound.
Functions
A function is a rule which maps a number or entity to another unique number or entity.
Let A and B be two non-empty sets. A function f from A to B is a relation from A to B such that:
(i) dom f = A i.e. f is defined at each a A.
(ii) if ( x, y f ) and ( x ,z f ) then y= z i.e. no element of A is related to two elements of B.
Note: 1. The words mapping, transformation, correspondence, and operator are used as
synonyms of function.
2. If f is a function from A to B, we write f: A→B.
Bijective Function: If a function is both one-to-one and onto then it is called a bijective
function.
--
Remark: A one-to-one, onto function f : A B is usually called a one-to-one
correspondence between A and B.
3. Since a function is a set, two functions f and g from A to B are equal if they are
equal as sets. In other words, f g iff f a g a for each a A .
Composition of Functions
The composition of a function is an operation where two functions say f and g generate a
new function say h in such a way that h x g f x .
It means here function g is applied to the function of x . So, basically, a function is applied
to the result of another function.
Definition: Let f : A B and g : B C be two functions. Then the composition of f and
g , denoted by g f , is defined as the function g f : A C given by g f x g f x ,
x A.
--
The below figure shows the representation of composite functions.
Note: The order of function is an important thing while dealing with the composition of
functions since f g x is not always equal to g f x .
1. Associative Property: If there are three functions f , g and h , then they are said to
be associative if and only if
f g h f g h
2. Commutative Property: Two functions f and g are said to be commute with each
other, if and only if
f gg f
--
Example: If f x 3 x , then f f x f f x f 3x 2 3.9 x 4 27 x 4 .
2
Inverse Function
Definition: An inverse function or an anti-function is defined as a function, which can
reverse into another function. In simple words, if any function f takes x to y then, the
inverse of f will take y to x.
y 5
Let f x 2 x 5 y x g y
2
x 5
Then, f 1 x .
2
Remark: In trigonometry, the inverse sine function is used to find the measure of angle for
which sine function generated the value.
For example, sin-1(1) = sin-1(sin 90) = 90 degrees. Hence, sin 90 degrees is equal to 1.
Note: A function that consists of its inverse fetches the original value.
Types of Inverse Function: There are various types of inverse functions like the inverse of
trigonometric functions, rational functions, hyperbolic functions and log functions. The
inverses of some of the most common functions are given below.
+ –
× / Don‟t divide by 0
x2 √y x and y ≥ 0
ex ln(y) y>0
--
Function Inverse of the Function Comment
Operations
We can classify the operations into following main categories:
Unary Operation: A unary operation is an operation with only one operand, i.e. a single
input.
Examples: The function f : A A , (where A is a set) is a unary operation on A. The
trigonometric functions are unary operations.
Notations: Common notations are prefix notation (e.g. +, −, ¬), postfix notation
(e.g. factorial n!), functional notation (e.g. sin x or sin(x)), and superscripts (e.g.
transpose AT).
Binary Operation: A binary operation or dyadic operation is a calculation that combines two
elements (called operands) to produce another element.
Examples: The familiar arithmetic operations of addition, subtraction, and multiplication.
Other examples are readily found in different areas of mathematics, such as vector addition
and matrix multiplication.
Also, picking out a maximum, minimum, mean, medium, the first object in a list and so on
are also its examples.
Remark: In general, a function takes an object from space X and maps it to space Y. If the
objects in X are tuples (an ordered collection of sub-objects) then the function is an n-ary
operation.
f : X Y
X X1 X 2 ... X n
then f is an n-ary operation.
--
SOLVED PROBLEMS
Example 1. Which of these sets are equal: {x, y, z}, {z, y, z, x}, {y, x, y, z}, {y, z, x, y}?
Solution: They are all equal. Order and repetition do not change a set.
--
(c) From Venn diagram, we can clearly see that 28+ 18 + 10 = 56 read exactly one of the
magazines.
Example 4. Given: A = {1, 2},B = {x, y, z}, and C = {3, 4}. Find: A × B × C.
Solution: A × B × C consists of all ordered triplets (a, b, c) where a ∈ A, b ∈ B, c ∈ C. These
elements of A × B × C can be systematically obtained by a so-called tree diagram as shown
below. The elements of A×B ×C are precisely the 12 ordered triplets to the right of the tree
diagram.
Example 6. If A = {1, 2, 3, 4} and B = {x, y, z}. Let R be the following relation from A to B:
R = {(1, y), (1, z), (3, y), (4, x), (4, z)}
(a) Determine the matrix of the relation.
(b) Draw the arrow diagram of R.
(c) Find the inverse relation R−1 of R.
--
(d) Determine the domain and range of R.
Solution:
(d) The domain of R, Dom(R), consists of the first elements of the ordered pairs of R, and the
range of R, Ran(R), consists of the second elements. Thus,
Dom(R) = {1, 3, 4} and Ran(R) = {x, y, z}
Example 7. Let X = {1, 2, 3, 4}. Determine whether each relation on X is a function from X
into X.
(a) f = {(2, 3), (1, 4), (2, 1), (3.2), (4, 4)}
(b) g = {(3, 1), (4, 2), (1, 1)}
(c) h = {(2, 1), (3, 4), (1, 4), (2, 1), (4, 4)}
Solution: Recall that a subset f of X×X is a function f: X → X if and only if each a ∈ X
appears as the first coordinate in exactly one ordered pair in f.
(a) No. Two different ordered pairs (2, 3) and (2, 1) in f have the same number 2 as their first
coordinate.
(b) No. The element 2 ∈ X does not appear as the first coordinate in any ordered pair in g.
(c) Yes. Although 2 ∈ X appears as the first coordinate in two ordered pairs in h, these two
ordered pairs are equal.
Example 8. Let A = {a, b, c}, B = {x, y, z},C = {r, s, t}. Let f: A → B and g: B → C be
defined by:
f = {(a, y), (b, x), (c, y)} and g = {(x, s), (y, t ), (z, r)}.
Find: (a) composition function g◦f: A → C; (b) Im(f ), Im(g), Im(g◦f ).
Solution: (a) Use the definition of the composition function to compute:
(g◦f )(a) = g(f (a)) = g(y) = t
(g◦f )(b) = g(f (b)) = g(x) = s
(g◦f )(c) = g(f (c)) = g(y) = t
--
That is g◦f = {(a, t ), (b, s), (c, t)}.
(b) Find the image points (or second coordinates):
Im(f ) = {x, y}, Im(g) = {r, s, t}, Im(g◦f ) = {s, t}.
Solution: (a) The function f : A → B is not onto since 3 ∈ B is not the image of any element
in A.
The function g : B → C is not onto since z ∈ C is not the image of any element in B.
The function h : C → D is onto since each element in D is the image of some element of C.
(b) The function f : A → B is not one-to-one since a and c have the same image 2.
The function g : B → C is one-to-one since 1, 2 and 3 have distinct images.
The function h : C → D is not one-to-one since x and z have the same image 4.
(c) No function is one-to-one and onto; hence no function is invertible.
--
UNIT-II: Mathematical Logic
Syllabus
• Declarative • Interrogative
• Exclamatory • Imperative
2 Connectives
Propostions are combined by means of connectives to form new propositions or statements.
They are
(i) not (ii) and (iii) or (iv) if .. then (v) If and only if
p ∼p
T F
F T
2.2 Conjunction (and)
If p and q are propositions, then “p and q” is also a proposition, which we represent as “p∧q”
and is called “Conjunction”. The conjunction “p ∧ q” is true only when p is true and q is
true. In all other cases it is false.
√
Example : p : 2 is an irrational number
q : 7 is a prime number
√
p ∧ q : 2 is an irrational number and 7 is a prime number
p q p∧q
T T T
T F F
F T F
F F F
p q p∨q
T T T
T F T
F T T
F F F
If the politician is elected, voters would expect this politician to lower taxes. Fur-
thermore, if the politician is not elected, then voters will not have any expectation that this
person will lower taxes, although the person may have sufficient influence to cause those
in power to lower taxes. It is only when the politician is elected but does not lower taxes
that voters can say that the politician has broken the campaign pledge. This last scenario
corresponds to the case when p is true but q is false in “p → q”.
Converse, Contrapositive and Inverse: We can form some new conditional state-
ments starting with a conditional statement “p → q”. In particular, there are three related
conditional statements that occur so often that they have special names.
Example: What are the contrapositive, the converse, and the inverse of the condi-
tional statement “The home team wins whenever it is raining“?
Solution: Since “q whenever p” is one of the ways to express the conditional state-
ment “p → q”, the original statement can be rewritten as
Contrapositive: “If the home team does not win, then it is not raining.”
Inverse: “If it is not raining, then the home team does not win.”
Note: Out of these three conditional statements formed from “p → q”, only the
contrapositive always has the same truth value as “p → q”.
2.5 Biconditional
If p and q are propositions, then the conjunction of conditionals p → q and q → p is called
“Biconditional” of p and q and is denoted by p ↔ q. Thus p ↔ q is same as (p → q)∧(q → p)
and is read as “p if and only if q”.
Example: “You can take the flight if and only if you buy a ticket.”
This statement is true if p and q are either both true or both false, that is, if you buy a
ticket and can take the flight or if you do not buy a ticket and you cannot take the flight. It
is false when p and q have opposite truth values, that is, when you do not buy a ticket, but
you can take the flight (such as when you get a free trip) and when you buy a ticket but you
cannot take the flight (such as when the airline bumps you).
3 Definitions
Compound Propositions: The new propositions obtained by using connectives are
called molecular or compound propositions.
Simple Propositions: Propositions which don’t contain any logical connectives are
called simple propositions.
Tautology: A compound proposition function which is true for all possible truth
values of its components is called “tautology”.
Example :
p ∼p p∨∼p p∧∼p
T F T F
F T T F
Hence, [ ( p → q ) ∧ ( q → r ) ] → ( p → r ) is a Tautology.
p q p→q ∼p ∼p∨q
T T T F T
T F F F F
F T T T T
F F T T T
We observe that p → q and ∼ p ∨ q have identical truth values for all possible truth values
of p and q.
∴ ( p → q) ⇔ ( ∼ p ∨ q) i.e., p → q and ∼ p ∨ q are logically equivalent.
Note: Much care must be taken not to confuse implication (or conditional) with
logical implication. The conditional is only a way of connecting the two propositions p and
q, whereasif p logically implies q then p and q are related to the extent that whenever p
has the truth value T then so does q. We do note that every logical implication is an
implication (conditional), but not all implications are logical implications.
Valid and Faulty Inferences: We say that an inference is valid if the implication
is a tautology, that is, if the implication is a logical implication otherwise, we say that the
inference is faulty or invalid.
Problem 7 Obtain the truth table for p ∨ (q ∧ r) and (p ∧ q) ∨ (p ∧ r) for all possible
truth values of p, q, r.
Solution : Do it yourself.
5 Fallacies
These are the statements which appear to be true but they are not. There are three forms
of faulty inferences.
1. Fallacy of affirming the Consequent :
p→q
q
∴ p is a Fallacy
since [(p → q) ∧ q] → p is not a tautology.
2. Fallacy of denying the antecedent :
p→q
∼p
∴ ∼q is a Fallacy
since [(p → q) ∧ (∼ p)] → (∼ q) is not a tautology.
3. Non sequitur fallacy (Non sequitur means it doesn’t follow) :
p
∴ q is a Fallacy
since p → q is not a tautology.
Solution : This can be done by using truth tables of both LHS and RHS or obtain RHS
from LHS by simplifying LHS.
( p → q ) ∧ [ ∼ q ∧ (r ∨ ∼ q)] ≡ ( p → q ) ∧ [ ∼ q ∧ (∼ q ∨ r)] Commutative Law
≡ (p→q )∧∼q Absorption Law
≡ ∼[(p→q )→q ] {∵∼(p→q )≡p∧∼q }
≡ ∼[∼(p→q )∨q ] {∵(p→q )≡∼p∨q }
≡ ∼[(p∧∼q )∨q ] {∵∼(p→q )≡p∧∼q }
≡ ∼ [ q ∨ ( p ∧ ∼ q ) ] Commutative Law
≡ ∼ [ (q ∨ p) ∧ ( q ∨ ∼ q ) ] Distributive Law
≡ ∼ [ (q ∨ p) ∧ T0 ] { ∵ q ∨ ∼ q is a Tautology }
≡ ∼ (q ∨ p) Identity Law
Solution : Let w = u ∨ v
3. Direct Proof : The direct proof begins by assuming p is true and then, from available
information, from the frame of reference, the conclusion q is shown to be true by valid
inference.
7. Proof by Elimination of Cases : This method of proof is nothing more than the
law of disjunctive syllogism, given by [ ( p ∨ q ) ∧ ∼ p ] → q. This can be extended to
any finite number of cases.
{ [ ( p1 ∨ p2 ∨ p3 ∨ p4 ....∨ pn ) ∨ q ] ∧ ∼ p1 ∧ ∼ p2 ∧ ∼ p3 ∧ ∼ p4 ...∧ ∼ pn } → q
Our target is to determine whether the aforementioned argument is correct or not. All
three are statements and are independent as no implication is there. Propositional logic
is not enough to handle these kinds of arguments therefore we’ll move to first-order logic.
We’ll identify the validity of such arguments using first-order logic or predicate logic. So
we’ll understand Predicates and Quantifiers.
Predicates: Predicates are statements involving variables which are neither True nor
False untill or unless the values of variables are specified.
Example:
1. x is an animal.
2. x is greater than 4.
3. x is less than 5
4. x + y = 7.
All the above statements are neither True nor False. They are not propositions because we
can’t identify thruth values for the argument.
In Predicate logic, a statement is devided into two parts: subject and predicate. Usually we
denote such statements with shorthand notation; G(x).
Quantifiers: Quantifiers are words that refer to quantities such as “some” or “all”. It tells
for howmany elements a given Predicate is True. In English, Quantifiers are used to express
the quantities without giving an exact number.
Ex. all. some, many, none, few etc.
Sentence like: —
Remark: If we use a quantifier that appears within the scope of another quantifier, then
it is called nested quantifier.
Example :
2. B(x) : x is a Bird.
Other Methods of Proof: We can write a few more proof techniques as:
1. Proof by example: To show ∃x, F (x) is true, it is sufficient to show F (c) is true
for some c in the universe. This type is the only situation where an example proves
anything.
2. Proof by exhaustion: A statement of the form ∀x, [∼ F (x)] that F (x) is false for all
x (all false) or, equivalently, that there are no values of x for which F (x) is true (none
true) will have been proven after all the objects in the universe have been examined
and none found with property F (x).
Assertion Reason
Assertion Reason
If we generalise this process, then there are 3 steps to a proof using the principle of
mathematical induction:
3. Inductive step : Show that P (k + 1) is true on the basis of the inductive hypothesis.
n(n + 1)
Example: Prove the formula for the sum of the first n positive integer.
2
Proof: Let S(n) = 1 + 2 + 3 + ... + n. The proof consists of following steps:
1. Basis of Induction : Since S(1) = 1 = 1(1 + 1)/2, the formula is true for n = 1.
2. Inductive hypothesis : Assume the statement S(n) is true for n = k, that is,
k(k + 1)
S(k) = 1 + 2 + 3 + ... + k = .
2
3. Inductive step : Now, show that the formula is true for n = k + 1, that is, S(k + 1) =
(k + 1)(k + 2)
follows from the inductive hypothesis.
2
To do this, we have S(k + 1) = 1 + 2 + 3 + ... + k + (k + 1) = S(k) + (k + 1)
k(k + 1)
Now, using inductive hypothesis S(k) = in above, we can write
2
k(k + 1) k
S(k + 1) = S(k) + (k + 1) = + (k + 1) = (k + 1)( + 1)
2 2
(k + 1)(k + 2)
S(k + 1) =
2
Hence the formula holds for (k + 1) and the proof is complete by the principle of
mathematical induction.
2. When k ≥ q, the assumption that P (i) is true for all integers 1 ≤ i ≤ k implies that
P (k + 1) is true.
As in the case of the principle of mathematical induction, this form can be modified
to apply to statements in which the starting value is an integer different from 1.
Thus, just as before, there are 3 steps to proof by strong mathematical induction:
2. Strong Inductive hypothesis : Assume P (i) is true for all integers i such that
1 ≤ i ≤ k where k ≥ q.
3. Inductive step : Show that P (k + 1) is true on the basis of the strong inductive
hypothesis.
Example: Prove that the function b(n) = 2(3)n − 5 is the unique function defined
by
Solution: First it is easy to check that b(n) = 2(3)n − 5 satisfies the given relations.
Next, we claim that if a(n) is any other function satisfying relations (1) and (2), then
a(n) = b(n) for all n.
We prove P (n) is a true statement for all non-negative integers n by strong induction.
1. Basis of Induction : Since we know b(0) = −3 and b(1) = 1 and we are assuming
a(0) = −3 and a(1) = 1. Thus, a(0) = b(0) and a(1) = b(1). Therefore, P (0) and P (1)
are true.
2. Strong Inductive hypothesis : Assume P (i) is true for all integers i such that
0 ≤ i ≤ k where k ≥ 1. In other words, assume a(i) = b(i) for all integers 0 ≤ i ≤ k
where k ≥ 1.
= (8)(3k ) − (6)(3k−1 ) − 5
= (8)(3k ) − 2(3k ) − 5
= (6)(3k ) − 5
= (2.3)(3k ) − 5
= (2)(3k+1 ) − 5
= b(k + 1)
Syllabus
Basics of Counting, Combinations and Permutations, Enumeration of Combinations and
Permutations, Enumerating Combinations and Permutations with Repetitions, Enumerating
Permutations with Constrained Repetitions, Binomial Coefficients, The Binomial and
Multinomial Theorems
Self-study Pascal’s Identity, Extended Binomial theorem
1 Introduction
For most applications of computers to problems,one normally needs to know, at least approx-
imately, how much storage will be required and about how many operations are necessary. A
major component of estimating the storage needed may be determining the number of items
of a particular type that have to be stored. Similarly, a knowledge of how many operations
the computation involves will help in assessing the length of program execution time, and
thereby aid in determining the potential cost of the computation. Being able to answer
such questions of the form “How many?”, is important if one attempts to compare differ-
ent methods of computation or even to decide whether or not a given computation is feasible.
• Arrangements of elements in a set into patterns satisfying specifc rules, generally re-
ferred to as discrete structures. Here discrete (as opposed to continuous) typically also
means finite, although we will consider some infnite structures as well.
2 Basics of Counting
If X is a set, let us use |X| to denote the number of elements in X.
Note: It is important to note that the subsets S1 , S2 , ... ,Sn must have no elements
in common. Moreover, since X = S1 ∪ S2 ∪ ... ∪ Sn , each element of X is in exactly one of
the subsets Si . In other words, S1 , S2 , ... ,Sn is a partition of X.
Example: In how many ways can we draw a heart or a spade from an ordinary deck
of playing cards? A heart or an ace? An ace or a king? A card numbered 2 through 10? A
numbered card or a king?
Solution: Since there are 13 hearts and 13 spades, we may draw a heart or a spade
in 13 + 13 = 26 ways.
We may draw a heart or an ace in 13 + 3 = 16 ways since there are only 3 aces that
are not hearts.
We may draw an ace or a king in 4 + 4 = 8 ways.
–
There are 9 cards numbered 2 through 10 in each of 4 suits, clubs, diamonds, hearts,
or spades, so we may choose a numbered card in 36 ways. (Note: we are counting aces as
distinct from numbered cards.)
Thus, we may choose a numbered card or a king in 36 + 4 = 40 ways.
Example: Suppose that the license plates of a certain state require 3 English letters
followed by 4 digits, (a) How many different plates can be manufactured if repetition of
letters and digits are allowed? (b) How many plates are possible if only the letters can be
repeated? (c) How many are possible if only the digits can be repeated? (d) How many are
possible if no repetitions are allowed at all?
Solution: (a) 263 · 104 since there are 26 possibilities for each of the 3 letters and 10
possibilities for each of the 4 digits.
(b) 263 · 10 · 9 · 8 · 7.
(c) 26 · 25 · 24 · 104 .
(d) 26 · 25 · 24 · 10 · 9 · 8 · 7.
Solution: First, determine the integers less than 109 that do not contain the digit 1.
We are considering 1-digit, or 2-digit, ... , up to 9-digit numbers. (Of course, a representation
like 000002578 is actually a 4-digit number so we can consider 9 positions to be filled with
any of the digits 0, 2, 3, 4, 5, 6, 7, 8, or 9. There are 99 such integers that do not contain
the digit 1.
Thus, there are 109 − 99 = 612, 579, 511 integers less than 109 that do contain the
digit 1.
–
of the first type.
Example: Suppose that there are 101 players entered in a single elimination tennis
tournament where any player who loses a match must drop out, and every match ends in
a victory for some player, that is, there are no ties. In each round of the tournament, the
players remaining are matched into as many pairs as possible, but if there is an odd number
of players left someone receives a bye (which means an automatic victory for this player in
this round). Enough rounds are played until a single player remains who wins the tourna-
ment. How many matches must be played in total?
Solution: Approach 1 - The 50 winners and bye will go into the second round and
pair into 25 matches and a bye. After this the 25 winners and the bye will go into the third
round where there will be exactly 13 matches. The fourth round will have six matches and
a bye; the fifth round, 3 matches and a bye; the sixth, 2 matches; the seventh will have 1
match and the winner of the seventh round wins the entire tournament. In total, there must
be 50 + 25 + 13 + 6 + 2 + 1 = 100 matches.
Remark: One of the nice features of the second approach is that the problem and
its solution can be generalized. Any single elimination tournament similar to the one above
that starts with n contestants will require n − 1 matches in order to determine a winner.
2.4 Factorials
Definition: For each positive integer we define n! = (n − 1).(n − 2)...3.2.1 = the product
of all integers from 1 to n.
We read n! as “n factorial.”
Remark: We are simply defining the terms r-combinations and r-permutations here
and have not mentioned anything about the properties of the n objects. For example, these
–
definitions say nothing about whether or not a given element may appear more than once
in the list of n objects.
Example: Suppose that the 5 objects from which selections are to be made are:
a, a, a, b, c.
Then, the 3-combinations of these 5 objects are: aaa, aab, aac, abc.
The 3-permutations are: aaa, aab, aba, baa, aac, aca, caa, abc, acb, bac, bca, cab, cba.
Remark: We will use expressions like {3·a, 2·b, 5·c} to indicate either (1) that
we have 3 + 2 + 5 = 10 objects including 3a0 s, 2b0 s and 5c0 s, or (2) that we have 3 objects
a, b, c where selections are constrained by the conditions that a can be selected at most three
times, b can be selected at most twice, and c can be chosen up to five times. The numbers
3, 2, and 5 in this example will be called repetition numbers.
Definition : If we are considering selections where each object has ∞ as its repeti-
tion number then we designate such selections as selections with unlimited repetitions.
In particular, a selection of r objects in this case will be called r-combinations with
unlimited repetitions and any ordered arrangement of these r objects will be a r-permutation
with unlimited repetitions.
aaa, aab, aac, aad, bbb, bba, bbc, bbd, ccc, cca, ccb, ccd, ddd, dda, ddb, ddc, abc, abd, acd, bcd
–
4.1 Theorem: Enumerating r-permutations without repetitions
n!
P (n, r) = n(n − 1)(n − 2)...(n − r + 1) =
(n − r)!
Proof: Since there are n distinct objects, the first position of a r-permutation may be
filled in n ways. Next, the second position can be filled in (n − 1) ways since no repetitions
are allowed and there are (n − 1) objects left to choose from. The third can be filled in
(n − 2) ways and soon until the rth position is filled in (n − r + 1) ways.
Example: In how many ways can 7 women and 3 men be arranged in a row if the
3 men must always stand next to each other?
Solution: There are 3! ways of arranging the 3 men. Since the 3 men always
stand next to each other, we treat them as a single entity, which we denote by X. Then if
W1 , W2 , ..., W7 represents the women, we next are interested in the number of ways of arrang-
ing X, W1 , W2 , ..., W7 . There are 8! permutations of these 8 objects. Hence there are (3!)(8!)
permutations altogether (of course, if there has to be a prescribed order of an arrangement
on the 3 men then there are only 8! total permutations).
Example: In how many ways can the letters of the English alphabet be arranged
so that there are exactly 5 letters between the letters a and b?
Solution: There are P (24, 5) ways to arrange the 5 letters between a and b ,2 ways
to place a and b, and then 20! ways to arrange any 7-letter word treated as one unit along
with the remaining 19 letters. The total is P (24, 5)(20!)(2).
Linear and Circular Permutations: If the objects are being arranged in a line
then the permutations are called linear permutations and if we arrange those in a circle then
the permutations are called circular permutations.
In circular permutations, the number of permutations decreases.
–
Solution: Here, the 5 children are not assigned to particular places but are only
arranged relative to oneanother. Thus, the arrangements are considered the same if the
children are in the same order clockwise. Hence, the position of child C1 is immaterial and
it is only the position of the 4 other children relative to C1 that counts. Therefore, keeping
C1 fixed in position, there are 4! arrangements of the remaining children.
Solution: For each of the 4 suits, spades, hearts, diamonds, or clubs, there are
C(13, 5) 5-card hands. Hence, there are a total of 4C(13, 5) such hands.
Example: There are 21 consonants and 5 vowels in the English alphabet. Consider
only 8-letter words with 3 different vowels and 5 different consonants, how many such words
can be formed?
Solution: Choose the vowels, choose the consonants, and then arrange the 8 letters.
Therefore, C(5, 3)C(21, 5)8! such words can be formed.
Example: There are 30 females and 35 males in the junior class while there are
25 females and 20 males in the senior class. In how many ways can a committee of 10 be
chosen so that there are exactly 5 females and 3 juniors on the committee?
–
Solution: Let us construct the following table:
Junior, Female Junior, Male Senior, Female Senior, Male No. of Ways of Selection
0 3 5 2 C(30,0)C(35,3)C(25,5)C(20,2)
1 2 4 3 C(30,1)C(35,2)C(25,4)C(20,3)
2 1 3 4 C(30,2)C(35,1)C(25,3)C(20,4)
3 0 2 5 C(30,3)C(35,0)C(25,2)C(20,5)
Thus, the total number of ways is the sum of the terms in the last column:
C(30, 0)C(35, 3)C(25, 5)C(20, 2) + C(30, 1)C(35, 2)C(25, 4)C(20, 3)+
C(30, 2)C(35, 1)C(25, 3)C(20, 4) + C(30, 3)C(35, 0)C(25, 2)C(20, 5).
Permutations
Proof: Each of the r positions can be filled in n ways and so by the product rule,
U (n, r) = nr .
Solution: 325 .
Example: The results of 50 football games (win, lose or, tie) are to be predicted.
How many different forecasts can contain exactly 28 correct results?
Solution: Choose 28 correct results C(50, 28) ways. Each of the remaining 22
games has 2 wrong forecasts. Thus, there are C(50, 28) · 222 forecasts with exactly 28 correct
predictions.
Combinations
Let a1 , a2 , ..., an be the distinct objects so that selections are made from {∞ · a1 , ∞ ·
a2 , ..., ∞ · an }. Any r-combination will be of the form {x1 · a1 , x2 · a2 , ..., xn · an } where
x1 , x2 , ..., xn are the repetition numbers, each xi is nonnegative, and x1 + x2 + ... + xn = r.
Conversely, any sequence of nonnegative integers x1 , x2 , ..., xn where x1 + x2 + ... + xn = r
corresponds to an r-combination {x1 · a1 , x2 · a2 , ..., xn · an }.
We summarize:
Example: How many different outcomes are possible by tossing 10 similar coins?
–
Solution: This is the same as placing 10 similar balls into two boxes labeled “heads”
and “tails”. Therefore, possible outcomes = C(2 − 1 + 10 , 10) = C(11, 10) = 11.
Solution: First, place one ball in each of the 5 boxes. Then we must count the
number of ways of distributing the 15 remaining balls into 5 boxes with unlimited repetitions.
Using previous theorem, we can do this in C(5 − 1 + 15, 15) = C(19, 15) ways.
Another Approach: We can also model this problem as a solution-of-an-equation
problem. If xi represents the number of balls in the ith box, then we are asked to enumerate
the number of integral solutions to x1 + x2 + x3 + x4 + x5 = 20. where each xi > 0 . After
distributing 1 ball into each of the 5 boxes, we then are to enumerate the number of integral
solutions of y1 + y2 + +y3 + y4 + y5 = 15 where each yi ≥ 0.
Let q1 , q2 , ..., qt are nonnegative integers such that n = q1 + q2 + ... + qt . Also, let us
consider that a1 , a2 , ..., at are t distinct objects. Let P (n; q1 , q2 , ..., qt ) denotes the number of
n-permutations of the n-combination {q1 · a1 , q2 · a2 , ..., qt · at }, then
n!
P (n; q1 , q2 , ..., qt ) =
q1 ! q2 ! ... qt !
Example: Find the number of arrangements of letters in the word TALLAHASSEE.
Solution: Choose the 2 students to receive 4 books each in C(5, 2) ways. Then to
23!
each such choice the 23 books can be distributed in P (23; 4, 4, 5, 5, 5) = ways.
4!4!5!5!5!
23!
Thus there are C(5, 2) · total distributions.
4!4!5!5!5!
7 Binomial Coefficients
In mathematics, the binomial coefficients are the positive integrs that occur as coefficients
in the binomial theorem.
In formulas arising from the analysis of algorithms in computer science, the binomial
coefficients occur over and over again, so that a facility for manipulating them is a necessity.
Moreover, different approaches to problems often give rise to formulas that are different in
appearance yet identities of binomial coefficients reveal that they are, in fact, the same ex-
pressions.
Remark: It might be instructive at this point to list some formulas for r-permutations
along with a combinatorial interpretation.
P (n, r) = nP (n − 1, r − 1)
–
7.6 Secondary Conditions
C(n, 1) = n = C(n, n − 1)
(x+y)n = C(n, 0)xn +C(n, 1)xn−1 y+C(n, 2)xn−2 y 2 +...+C(n, r)xn−r y r +...+C(n, n)y n
n n n n n
n n−2 2
(x + y)n = 0
x + 1
xn−1 y + 2
x y + ... + r
xn−r y r + ... + n
yn
Pn
(x + y)n = r=0 C(n, r)xn−r y r
–
n
Note: The binomial coefficients C(n, r) = r
receive their name from their appear-
ance in the expansion of powers of a binomial.
Example: (x + y)8 = C(8, 0)x8 + C(8, 1)x7 y + C(8, 2)x6 y 2 + C(8, 3)x5 y 3
+C(8, 4)x4 y 4 +C(8, 5)x3 y 5 +C(8, 6)x2 y 6 +C(8, 7)xy 7 +C(8, 8)y 8
+8xy 7 + y 8 .
Solution: There are C(10 + 5 − 1, 10) = C(14, 10) = 1001 terms in the expansion
(x1 + x2 + x3 + x4 + x5 )10 .
10!
The required coefficient is P (10; 2, 0, 1, 3, 4) = = 12600.
2!0!1!3!4!
–
UNIT-IV: Advanced Counting
Techniques
Syllabus
The simplest form of a recurrence relation is the case where the next term depends
only on the immediately previous term. If we denote the nth term in the sequence by xn , such
a recurrence relation is of the form xn+1 = f (xn ) for some function f . One such example is
xn+1 = 2 − xn /2.
A recurrence relation can also be of higher order, where the term xn+1 could depend
not only on the previous term xn but also on earlier terms such as xn−1 , xn−2 etc. A second
order recurrence relation depends just on xn and xn−1 and is of the form xn+1 = f (xn , xn−1 )
for some function f with two inputs. For example, the recurrence relation xn+1 = xn + xn−1
can generate the Fibonacci numbers.
To generate sequence based on a recurrence relation, one must start with some initial
values. For a first order recursion xn+1 = f (xn ), one just needs to start with an initial value
x0 and can generate all remaining terms using the recurrence relation. For a second order
recursion xn+1 = f (xn , xn−1 ), one needs to begin with two values x0 and x1 . Higher order
recurrence relations require correspondingly more initial values.
Example: The recurrence relation an = an−1 + a2n−2 is not linear. The recurrence
relation Hn = 2Hn−1 + 1 is not homogeneous. The recurrence relation Bn = nBn−1 does not
have constant coefficients.
Note: Linear homogeneous recurrence relations are studied for two reasons. First,
they often occur in modeling of problems. Second, they can be systematically solved.
Example: What is the solution of the recurrence relation an = an−1 + 2an−2 with
a0 = 2 and a1 = 7?
Solution: The characteristic equation of the recurrence relation is r2 − r − 2 = 0. Its
roots are r = 2 and r = −1. Hence, the sequence an is a solution to the recurrence relation if
and only if an = α1 2n + α2 (−1)n , for some constants α1 and α2 . From the initial conditions,
it follows that a0 = 2 = α1 + α2 , a1 = 7 = α1 · 2 + α2 · (−1).
Solving these two equations shows that α1 = 3 and α2 = −1. Hence, the solution to
the recurrence relation and initial conditions is the sequence an with an = 3 · 2n − (−1)n .
α1 = √1 , α2 = − √15 .
5
Example: What is the solution of the recurrence relation an = 6an−1 − 9an−2 with
initial conditions a0 = 1 and a1 = 6?
Solution: Do it yourself. Answer - an = 3n + n3n .
Example: Find the solution to the recurrence relation an = −3an−1 − 3an−2 − an−3
with initial conditions a0 = 1, a1 = −2, and a2 = −1.
Solution: Do it yourself. Answer - an = (1 + 3n − 2n2 )(−1)n .
Note: The key fact about linear nonhomogeneous recurrence relations with constant
coefficients is that every solution is the sum of a particular solution and a solution of the
associated linear homogeneous recurrence relation.
Example: Find all solutions of the recurrence relation an = 3an−1 + 2n. What is the
solution with a1 = 3?
Solution: The associated linear homogeneous equation is an = 3an−1 . Its solutions
(h)
are an = α 3n , where α is a constant.
We now find a particular solution. Because F (n) = 2n is a polynomial in n of degree
one, a reasonable trial solution is a linear function in n, say, pn = cn + d, where c and d are
constants.
To determine whether there are any solutions of this form, suppose that pn = cn + d
is such a solution. Then the equation an = 3an−1 + 2n becomes cn + d = 3(c(n − 1) + d) + 2n.
Simplifying and combining like terms gives (2 + 2c)n + (2d − 3c) = 0. It follows that
cn + d is a solution if and only if 2 + 2c = 0 and 2d − 3c = 0.
This shows that cn+d is a solution if and only if c = −1 and d = −3/2. Consequently,
(p)
an = −n − 3/2 is a particular solution.
(p) (h) 3
Therefore, the final solutions can be written as an = an + an = −n − + α · 3n ,
2
where α is a constant.
To find the solution with a1 = 3, let n = 1 in the formula we obtained for the general
3
solution. We find that 3 = −1 − + 3α, which implies that α = 11/6. So, the solution we
2
3 11 n
seek is an = −n − + 3 .
2 6
Example: Find all solutions of the recurrence relation an = 5an−1 − 6an−2 + 7n .
49
Solution: Do it yourself. Answer - an = α1 · 3n + α2 · 2n + 7n .
20
Example - Binary Search The binary search algorithm reduces the search for an
element in a search sequence of size n to the binary search for this element in a search
sequence of size n/2, when n is even. (Hence, the problem of size n has been reduced to
one problem of size n/2.) Two comparisons are needed to implement this reduction (one to
determine which half of the list to use and the other to determine whether any terms of the
list remain). Hence, if f (n) is the number of comparisons required to search for an element
in a search sequence of size n, then f (n) = f (n/2) + 2 when n is even.
4 Generating Function
Generating functions are used to represent sequences efficiently by coding the terms of a
sequence as coefficients of powers of a variable x in a formal power series. Generating func-
tions can be used to solve many types of counting problems, such as the number of ways
to select or distribute objects of different kinds, subject to a variety of constraints, and the
number of ways to make change for a dollar using coins of different denominations. Gener-
ating functions can be used to solve recurrence relations by translating a recurrence relation
for the terms of a sequence into an equation involving a generating function. This equation
can then be solved to find a closed form for the generating function. From this closed form,
the coefficients of the power series for the generating function can be found, solving the
original recurrence relation. Generating functions can also be used to prove combinatorial
identities by taking advantage of relatively simple relationships between functions that can
be translated into identities involving the terms of sequences. Generating functions are a
helpful tool for studying many properties of sequences besides those described in this section,
such as their use for establishing asymptotic formulae for the terms of a sequence.
Remark: The generating function for ak given in above definition is sometimes called
the ordinary generating function of ak to distinguish it from other types of generating func-
tions for this sequence.
Example: Solve the recurrence relation ak = 3ak−1 for k = 1, 2, 3, ... and initial
condition a0 = 2.
Solution: Let G(x) is generating function for the sequence ak , i.e. G(x) = ∞ k
P
k=0 ak x .
Consequently, ak = 2 · 3k .
4.3 Proving Identities via Generating Functions
Combinatorial identities can be established using combinatorial proofs and generating func-
tions.
Pn
Example: Use generating functions to show that k=0 C(n, k)2 = C(2n, n) when-
ever n is a positive integer.
Solution: First note that by the binomial theorem C(2n, n) is the coefficient of xn
in (1 + x)2n .
(1 + x)2n = [(1 + x)n ]2 = [C(n, 0) + C(n, 1)x + C(n, 2)x2 + ... + C(n, n)xn ]2 .
5 Inclusion-Exclusion
5.1 The Principle of Inclusion-Exclusion
The number of elements in the union of the two sets A and B is the sum of the numbers of
elements in the sets minus the number of elements in their intersection.
Mathematically, |A ∪ B| = |A| + |B| − |A ∩ B|.
Example: Suppose that there are 1807 freshmen at your school. Of these, 453
are taking a course in computer science, 567 are taking a course in mathematics, and 299
are taking courses in both computer science and mathematics. How many are not taking a
course either in computer science or in mathematics?
Solution: To find the number of freshmen who are not taking a course in either
mathematics or computer science, subtract the number that are taking a course in either of
these subjects from the total number of freshmen. Let A be the set of all freshmen taking a
course in computer science, and let B be the set of all freshmen taking a course in mathe-
matics. It follows that |A| = 453, |B| = 567, and |A ∩ B| = 299. The number of freshmen
taking a course in either computer science or mathematics is
Consequently, there are 1807 - 721 = 1086 freshmen who are not taking a course in
computer science or mathematics.
Example: A total of 1232 students have taken a course in Spanish, 879 have taken
a course in French, and 114 have taken a course in Russian. Further, 103 have taken courses
in both Spanish and French, 23 have taken courses in both Spanish and Russian, and 14
have taken courses in both French and Russian. If 2092 students have taken at least one of
Spanish, French, and Russian, how many students have taken a course in all three languages?
Solution: Do it yourself. Answer - 7.
Example: How many onto functions are there from a set with six elements to a set
with three elements?
Solution: The required number is 36 − C(3, 1)26 + C(3, 2)16 = 729 − 192 + 3 = 540.
5.2.2 Derangements
A derangement is a permutation of objects that leaves no object in its original position. The
principle of inclusion-exclusion can be used to count the permutations of n objects that leave
no objects in their original positions.
Syllabus
Graphs and Graph Models, Graph Terminology and Special Types of Graphs,
Representing Graphs and Graph Isomorphism, Connectivity, Euler and Hamilton Paths,
Shortest-Path Problems, Planar Graphs, Graph Colouring.
2. A graph in which each edge connects two different vertices and where no two edges
connect the same pair of vertices is called a simple graph.
3. Graphs that may have multiple edges connecting the same vertices are called
multigraphs. When there are m different edges associated to the same unordered pair of
vertices u, v, we also say that u, v is an edge of multiplicity m.
4. When edges connect a vertex to itself, then such edges are called loops, and
sometimes we may even have more than one loop at a vertex.
5. Graphs that may include loops, and possibly multiple edges connecting the same
pair of vertices or a vertex to itself, are sometimes called pseudographs.
Definition: A directed graph (or digraph) (V, E) consists of a nonempty set of ver-
tices V and a set of directed edges (or arcs) E. Each directed edge is associated with an
ordered pair of vertices. The directed edge associated with the ordered pair (u, v) is said to
start at u and end at v.
Remarks: 1. When a directed graph has no loops and has no multiple directed
edges, it is called a simple directed graph.
2. Directed graphs that may have multiple directed edges from a vertex to a second
(possibly the same) vertex are called directed multigraphs. When there are m directed
edges, each associated to an ordered pair of vertices (u, v), we say that (u, v) is an edge of
multiplicity m.
Note: A graph with both directed and undirected edges is called a mixed graph.
For example, a mixed graph might be used to model a computer network containing links
that operate in both directions and other links that operate only in one direction.
Remark: This terminology for the various types of graphs is given in Table 1. We
will sometimes use the term graph as a general term to describe graphs with directed or undi-
rected edges (or both), with or without loops, and with or without multiple edges. At other
times, when the context is clear, we will use the term graph to refer only to undirected graphs.
2 Graph Models
Graphs are used in a wide variety of models as following:
2.7 Tournaments
Graphs can also be used to model different kinds of tournaments.
Example: Single-Elimination Tournaments A tournament where each con-
testant is eliminated after one loss is called a single-elimination tournament. We can model
such a tournament using a vertex to represent each game and a directed edge to connect a
game to the next game the winner of this game played in.
3 Graph Terminology
There are some terminology that describes the vertices and edges of undirected graphs.
Definition: The set of all neighbors of a vertex v of G = (V, E), denoted by N (v),
is called the neighborhood of v.
Note: This applies even if multiple edges and loops are present.
4.2 Cycles
A cycle Cn , n ≥ 3, consists of n vertices v1 , v2 , ..., vn and edges v1 , v2 , v2 , v3 , ..., vn−1 , vn , and
vn , v1 . The cycles C3 , C4 , C5 , and C6 are displayed in the following figure.
4.3 Wheels
We obtain a wheel Wn when we add an additional vertex to a cycle Cn , for n ≥ 3, and
connect this new vertex to each of the n vertices in Cn , by new edges. The wheels W3 , W4 ,
W5 , and W6 are displayed in the following figure.
4.4 n-Cubes
An n-dimensional hypercube, or n-cube, denoted by Qn , is a graph that has vertices repre-
senting the 2n bit strings of length n. Two vertices are adjacent if and only if the bit strings
that they represent differ in exactly one bit position. We display Q1 , Q2 , and Q3 in the
following figure.
4.5 Bipartite Graphs
Definition: A simple graph G is called bipartite if its vertex set V can be partitioned into
two disjoint sets V1 and V2 such that every edge in the graph connects a vertex in V1 and a
vertex in V2 (so that no edge in G connects either two vertices in V1 or two vertices in V2 ).
When this condition holds, we call the pair (V1 , V2 ) a bipartition of the vertex set V
of G.
Example: C6 is bipartite, as shown in the following figure, because its vertex set
can be partitioned into the two sets V1 = v1 , v3 , v5 and V2 = v2 , v4 , v6 , and every edge of C6
connects a vertex in V1 and a vertex in V2 .
Result: A simple graph is bipartite if and only if it is possible to assign one of two
different colors to each vertex of the graph so that no two adjacent vertices are assigned the
same color.
Definition: A complete bipartite graph Km,n is a graph that has its vertex set partitioned
into two subsets of m and n vertices, respectively with an edge between two vertices if and
only if one vertex is in the first subset and the other vertex is in the second subset.
The complete bipartite graphs K2,3 , K3,3 , K3,5 , and K2,6 are displayed in the following figure.
Applications of Special Types of Graphs
Example: Use adjacency lists to describe the simple graph given in following figure:
Solution: Table 1 lists those vertices adjacent to each of the vertices of the graph.
Carrying out graph algorithms using the representation of graphs by lists of edges, or by
adjacency lists, can be cumbersome if there are many edges in the graph. To simplify
computation, graphs can be represented using matrices. Two types of matrices commonly
used to represent graphs will be presented here. One is based on the adjacency of vertices,
and the other is based on incidence of vertices and edges.
Example: Represent the graph shown on the next page with an incidence matrix.
6 Connectivity
Many problems can be modeled with paths formed by traveling along the edges of graphs.
Path: A path is a sequence of edges that begins at a vertex of a graph and travels
from vertex to vertex along edges of the graph. As the path travels along its edges, it visits
the vertices along this path, that is, the endpoints of these edges.
Circuit: A path of length n ≥ 1 that begins and ends at the same vertex is called
circuit.
Connectedness in Undirected Graphs: An undirected graph is called connected
if there is a path between every pair of distinct vertices of the graph. An undirected graph
that is not connected is called disconnected. We say that we disconnect a graph when we
remove vertices or edges, or both, to produce a disconnected subgraph.
Applications of Euler Paths and Circuits: Euler paths and circuits can be used to
solve many practical problems. For example, many applications ask for a path or circuit
that traverses each street in a neighborhood, each road in a transportation network, each
connection in a utility grid, or each link in a communications network exactly once. Find-
ing an Euler path or circuit in the appropriate graph model can solve such problems. For
example, if a postman can find an Euler path in the graph that represents the streets the
postman needs to cover, this path produces a route that traverses each street of the route
exactly once. If no Euler path exists, some streets will have to be traversed more than once.
7.2 Hamilton Path and Hamilton Circuit
A path which contains every vertex of graph G exactly once is called Hamiltonian graph.
A circuit that passes through each of the vertex in graph G exactly once except start-
ing vertex and ending vertex is called Hamiltonian circuit.
Applications of Hamilton Paths and Circuits: Hamilton paths and circuits can be
used to solve practical problems. For example, many applications ask for a path or circuit
that visits each road intersection in a city, each place pipelines intersect in a utility grid, or
each node in a communications network exactly once. Finding a Hamilton path or circuit
in the appropriate graph model can solve such problems. The famous traveling salesperson
problem or TSP asks for the shortest route a traveling salesperson should take to visit a set
of cities. This problem reduces to finding a Hamilton circuit in a complete graph such that
the total weight of its edges is as small as possible.
Question: Show that the following graph has Eulerian circuit but it does not have Hamil-
tonian circuit.
8 Shortest-Path Problems
Many problems can be modeled using graphs with weights assigned to their edges.
Weighted Graphs: Graphs that have a number assigned to each edge are called
weighted graphs.
Example: What is the length of a shortest path between a and z in the weighted
graph shown below?
We will solve this problem by finding the length of a shortest path from a to successive
vertices, until z is reached. The only paths starting at a that contain no vertex other than a
are formed by adding an edge that has a as one endpoint. These paths have only one edge.
They are a, b of length 4 and a, d of length 2. It follows that d is the closest vertex to a,
and the shortest path from a to d has length 2.
We can find the second closest vertex by examining all paths that begin with the
shortest path from a to a vertex in the set {a, d}, followed by an edge that has one endpoint
in {a, d} and its other endpoint not in this set. There are two such paths to consider, a, d, e
of length 5 and a, b of length 4. Hence, the second closest vertex to a is b and the shortest
path from a to b has length 4.
To find the third closest vertex to a, we need to examine only the paths that begin
with the shortest path from a to a vertex in the set {a, d, b}, followed by an edge that has
one endpoint in the set {a, d, b} and its other endpoint not in this set. There are three such
paths, a, b, c of length 7, a, b, e of length 7, and a, d, e of length 5. Because the shortest of
these paths is a, d, e, the third closest vertex to a is e and the length of the shortest path
from a to e is 5.
To find the fourth closest vertex to a, we need to examine only the paths that begin
with the shortest path from a to a vertex in the set {a, d, b, e}, followed by an edge that
has one endpoint in the set {a, d, b, e} and its other endpoint not in this set. There are two
such paths, a, b, c of length 7 and a, d, e, z of length 6. Because the shorter of these paths is
a, d, e, z, the fourth closest vertex to a is z and the length of the shortest path from a to z
is 6.
9 Planar Graphs
A graph is called planar if it can be drawn in the plane without any edges crossing (where
a crossing of edges is the intersection of the lines or arcs representing them at a point other
than their common endpoint). Such a drawing is called a planar representation of the graph.
Note: A graph may be planar even if it is usually drawn with crossings, because it
may be possible to draw it in a different way without crossings.
Euler’s Formula: Let G be a connected planar simple graph with e edges and v
vertices. Let r be the number of regions in a planar representation of G. Then
r = e − v + 2.
Example: Suppose that a connected planar simple graph has 20 vertices, each of
degree 3. Into how many regions does a representation of this planar graph split the plane?
Solution: This graph has 20 vertices, each of degree 3, so v = 20. Because the sum
of the degrees of the vertices, 3v = 3 ∗ 20 = 60, is equal to twice the number of edges, 2e,
we have 2e = 60, or e = 30.
Consequently, from Euler’s formula, the number of regions is
r = e − v + 2 = 30 − 20 + 2 = 12.
10 Graph Colouring
A coloring of a simple graph is the assignment of a color to each vertex of the graph so that
no two adjacent vertices are assigned the same color.
Example: Which of the graphs shown in the following figure are trees?
Solution: G1 and G2 are trees, because both are connected graphs with no simple
circuits. G3 is not a tree because e, b, a, d, e is a simple circuit in this graph. Finally, G4 is
not a tree because it is not connected.
Result: An undirected graph is a tree if and only if there is a unique simple path
between any two of its vertices.
Rooted Tree: A rooted tree is a tree in which one vertex has been designated as
the root and every edge is directed away from the root.
Binary Tree: A binary tree is defined as a tree in which there is exactly one vertex of
degree two, and each of remaining vertices is of degree one or three. The vertex of degree
two serves as a root.
Pendant Vertex in Tree: A vertex of degree one is called pendant vertex of tree. In
the following graph vertices 1, 1 and 5 are pendants.
Path Lenghth of Tree: A path length of a tree is defined as the sum of edges from
the root of all pendant vertices.
Path lenght of the following tree is:
2+2+2=6
12 Applications of Trees
• Storing hierarchical data
Solution: Figure 1 displays the steps to construct this binary search tree. The
word mathematics is the key of the root. Because physics comes after mathematics (in
alphabetical order), add a right child of the root with key physics. Because geography comes
before mathematics, add a left child of the root with key geography. Next, add a right child
of the vertex with key physics, and assign it the key zoology, because zoology comes after
mathematics and after physics. Similarly, add a left child of the vertex with key physics
and assign this new vertex the key meteorology. Add a right child of the vertex with key
geography and assign this new vertex the key geology.Add a left child of the vertex with key
zoology and assign it the key psychology. Add a left child of the vertex with key geography
and assign it the key chemistry.
13 Tree Traversal
Traversal Algorithms: Procedures for systematically visiting every vertex of an ordered
rooted tree are called traversal algorithms.
We will describe three of the most commonly used such algorithms, preorder traversal,
inorder traversal, and postorder traversal. Each of these algorithms can be defined recur-
sively.
Prefix (or Polish) notation: The form of an expression obtained from a preorder
traversal of the tree representing this expression.
Postfix (or reverse Polish) notation: The form of an expression obtained from
a postorder traversal of the tree representing this expression.
14 Spanning Trees
Definition: Let G be a simple graph. A spanning tree of G is a subgraph of G that is a
tree containing every vertex of G.
Working Rule:
• Start exploring all adjacent vertices connected through the selected vertex.
• Take vertices in any order and continue exploration untill all vertices are included.
Depth-first search, or backtracking: A procedure for constructing a spanning
tree by adding edges that form a path until this is not possible, and then moving back up
the path until a vertex is found where a new path can be formed.
Working Rule:
• Like pre-order traverse, once we go to new vertex, we will suspend this vertex and start
exploring new verex .
Working Rule:
• At each step, choose the edge whose inclusion will not create a circuit.
Example: In the following graph, the green colour one is minimal spanning tree (MST) by
Kruskal’s algorithm.
Working Rule:
• Select any vertex, choose an edge and smallest weight from G.
• At each stage, choose the edge of smallest weight joining a vertex already included to
vertex not yet included.