Introduction of Sets
Introduction of Sets
A set is defined as a collection of distinct objects of the same type or class of objects. The
purposes of a set are called elements or members of the set. An object can be numbers,
alphabets, names, etc.
b. A set of vowels.
Sets Representation:
a) Roster or tabular form: In this form of representation we list all the elements of the
set within braces { } and separate them by commas.
Example: If A= set of all odd numbers less then 10 then in the roster from it can be
expressed as A={ 1,3,5,7,9}.
b) Set Builder form: In this form of representation we list the properties fulfilled by all
the elements of the set. We note as {x: x satisfies properties P}. and read as 'the set of
those entire x such that each x has properties P.'
Standard Notations:
x∈A x belongs to A or x is an element of set A.
∅ Empty Set.
U Universal Set.
Q, Q0, Q+ The sets of rational, non- zero rational, +ve rational numbers respectively.
R, R0, R+ The set of real, non-zero real, +ve real number respectively.
Cardinality of a Sets:
The total number of unique elements in the set is called the cardinality of the set. The
cardinality of the countably infinite set is countably infinite.
Examples:
1. Let P = {k, l, m, n}
The cardinality of the set P is 4.
Types of Sets
Sets can be classified into many categories. Some of which are finite, infinite, subset,
universal, proper, power, singleton set, etc.
1. Finite Sets: A set is said to be finite if it contains exactly n distinct element where n
is a non-negative integer. Here, n is said to be "cardinality of sets." The cardinality of sets
is denoted by|A|, # A, card (A) or n (A).
Example:
A set is called a finite set if there is one to one correspondence between the elements in
the set and the element in some set n, where n is a natural number and n is the
cardinality of the set. Finite Sets are also called numerable sets. n is termed as the
cardinality of sets or a cardinal number of sets.
Countable Infinite: If there is one to one correspondence between the elements in set
and element in N. A countably infinite set is also known as Denumerable. A set that is
either finite or denumerable is known as countable. A set which is not countable is known
as Uncountable. The set of a non-negative even integer is countable Infinite.
Uncountable Infinite: A set which is not countable is called Uncountable Infinite Set or
non-denumerable set or simply Uncountable.
Example: Set R of all +ve real numbers less than 1 that can be represented by the
decimal form 0. a1,a2,a3..... Where a1 is an integer such that 0 ≤ ai ≤ 9.
Properties of Subsets:
1. Every set is a subset of itself.
Example:
A is a proper subset of B.
Example
A is an improper subset of B.
6. Universal Set: If all the sets under investigations are subsets of a fixed set U, then
the set U is called Universal Set.
Example: In the human population studies the universal set consists of all the people in
the world.
7. Null Set or Empty Set: A set having no elements is called a Null set or void set. It is
denoted by∅.
9. Equal Sets: Two sets A and B are said to be equal and written as A = B if both have
the same elements. Therefore, every element which belongs to A is also an element of
the set B and every element which belongs to the set B is also an element of the set A.
1. A = B ⟺ {x ϵ A ⟺ x ϵ B}.
If there is some element in set A that does not belong to set B or vice versa then A ≠ B,
i.e., A is not equal to B.
10. Equivalent Sets: If the cardinalities of two sets are equal, they are called
equivalent sets.
Example: If A= {1, 2, 6} and B= {16, 17, 22}, they are equivalent as cardinality of A is
equal to the cardinality of B. i.e. |A|=|B|=3
11. Disjoint Sets: Two sets A and B are said to be disjoint if no element of A is in B and
no element of B is in A.
Example:
R = {a, b, c}
S = {k, p, m}
12. Power Sets: The power of any given set A is the set of all subsets of A and is
denoted by P (A). If A has n elements, then P (A) has 2n elements.
Example: A = {1, 2, 3}
P (A) = {∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}.
Partitions of a Set:
Fig: Venn diagram of a partition of the rectangular set S of points into five
cells,A1,A2,A3,A4,A5
Venn Diagrams:
Venn diagram is a pictorial representation of sets in which an enclosed area in the plane
represents sets.
Examples:
Operations on Sets
1. Union of Sets: Union of Sets A and B is defined to be the set of all those elements
which belong to A or B or both and is denoted by A∪B.
1. A∪B = {x: x ∈ A or x ∈ B}
2. Intersection of Sets: Intersection of two sets A and B is the set of all those elements
which belong to both A and B and is denoted by A ∩ B.
1. A ∩ B = {x: x ∈ A and x ∈ B}
1. A - B = {x: x ∈ A and x ∉ B}
i.e.
1. A ⨁ B = (A ∪ B) - (A ∩ B)
A ⨁ B = {c, d, l, m}
B = {a, b, l, m}
Algebra of Sets
Sets under the operations of union, intersection, and complement satisfy various laws (identities) which are
listed in Table 1.
∪ ∅
(b) A ∪ U = U (d) A ∩ ∅ = ∅
Identity Laws (a) A = A (c) A ∩ U =A
∪ ∅
(b) A ∩ Ac= ∅ (d) ∅c = U
Complement (a) A Ac= U (c) U c=
Laws
Multisets
Example:
1. A = {l, l, m, m, n, n, n, n}
2. B = {a, a, a, a, a, c}
Operations on Multisets
1. Union of Multisets: The Union of two multisets A and B is a multiset such that the
Example:
1. Let A = {l, l, m, m, n, n, n, n}
2. B = {l, m, m, m, n},
3. A ∪ B = {l, l, m, m, m, n, n, n, n}
2. Intersections of Multisets: The intersection of two multisets A and B, is a multiset
such that the multiplicity of an element is equal to the minimum of the multiplicity of an
element in A and B and is denoted by A ∩ B.
Example:
1. Let A = {l, l, m, n, p, q, q, r}
2. B = {l, m, m, p, q, r, r, r, r}
3. A ∩ B = {l, m, p, q, r}.
Example:
1. Let A = {l, m, m, m, n, n, n, p, p, p}
2. B = {l, m, m, m, n, r, r, r}
3. A - B = {n, n, p, p, p}
4. Sum of Multisets: The sum of two multisets A and B, is a multiset such that the
multiplicity of an element is equal to the sum of the multiplicity of an element in A and B
Example:
1. Let A = {l, m, n, p, r}
2. B = {l, l, m, n, n, n, p, r, r}
3. A + B = {l, l, l, m, m, n, n, n, n, p, p, r, r, r}
Example:
1. A = {l, l, m, m, n, n, n, p, p, p, p, q, q, q}
Ordered Set
Example:
1. Roll no {3, 6, 7, 8, 9}
2. Week Days {S, M, T, W, W, TH, F, S, S}
Ordered Pairs
An Ordered Pair consists of two elements such that one of them is designated as the first
member and other as the second member.
(a, b) and (b, a) are two different ordered pair. An ordered triple can also be written
regarding an ordered pair as {(a, b) c}
An ordered Quadrable is an ordered pair {(((a, b), c) d)} with the first element as ordered
triple.
1. {(n -1), n}
Inclusion-Exclusion Principle
Example 1:
Example 2:
In a town of 10000 families it was found that 40% of families buy newspaper A, 20%
family buy newspaper B, 10% family buy newspaper C, 5% family buy newspaper A and
B, 3% family buy newspaper B and C and 4% family buy newspaper A and C. If 2% family
buy all the newspaper. Find the number of families which buy
Solution:
1. Number of families which buy all three newspapers:
1. = 40 - 7 = 33%
1. = 20 - 6 = 14%
1. = 10 - 5 = 5%
n (A ∪B ∪C)c = 100 - n (A ∪ B ∪ C)
n (A ∪B ∪C)c = 100 - [40 + 20 + 10 - 5- 3- 4 + 2]
n (A ∪B ∪C)c = 100 - 60 = 40 %
1. = 33 + 14 + 5 = 52%
1. = 3%
1. = 2%
1. = 8%
1. = 98%
1. = 6%
Mathematical Induction
The process to establish the validity of an ordinary result involving natural numbers is
the principle of mathematical induction.
Working Rule
Let n0 be a fixed integer. Suppose P (n) is a statement involving the natural number n
and we wish to prove that P (n) is true for all n ≥n 0.
Example 1:
1 + 3 + 5 +.... + 2n - 1 = n2.
Example 2:
12 + 22 + 32 +.......+ n2 =
Solution: For n = 1,
P (1) = 12 = =1
It is true for n = 1.
Solution:
Example1: If a set has n elements, how many relations are there from A to A.
Solution: If a set A has n elements, A x A has n 2 elements. So, there are 2n2 relations
from A to A.
Example2: If A has m elements and B has n elements. How many relations are there
from A to B and vice versa?
Solution: There are 22= 4 elements i.e., {(1, 2), (2, 1), (1, 1), (2, 2)} in A x A. So, there
are 24= 16 relations from A to A. i.e.
1. {(1, 2), (2, 1), (1, 1), (2, 2)}, {(1, 2), (2, 1)}, {(1, 2), (1, 1)}, {(1, 2), (2, 2)},
2. {(2, 1), (1, 1)},{(2,1), (2, 2)}, {(1, 1),(2, 2)},{(1, 2), (2, 1), (1, 1)}, {(1, 2), (1, 1),
3. (2, 2)}, {(2,1), (1, 1), (2, 2)}, {(1, 2), (2, 1), (2, 2)}, {(1, 2), (2, 1), (1, 1), (2, 2)} a
nd ∅.
Domain and Range of Relation
Domain of Relation: The Domain of relation R is the set of elements in P which are
related to some elements in Q, or it is the set of all first entries of the ordered pairs in R.
It is denoted by DOM (R).
Range of Relation: The range of relation R is the set of elements in Q which are related
to some element in P, or it is the set of all second entries of the ordered pairs in R. It is
denoted by RAN (R).
Example:
1. Let A = {1, 2, 3, 4}
2. B = {a, b, c, d}
3. R = {(1, a), (1, b), (1, c), (2, b), (2, c), (2, d)}.
Solution:
Example:
Solution:
X x Y = {(1, 8), (2, 8), (3, 8), (1, 9), (2, 9), (3, 9)}
Now we find the complement relation R from X x Y
R = {(3, 8), (2, 9)}
Representation of Relations
Mij = 0 if (ai,bj) ∉ R
1 if (ai,bj )∈ R
Example
Example
1. A = {1, 2, 3, 4}
2. R = {(1, 2) (2, 2) (2, 4) (3, 2) (3, 4) (4, 1) (4, 3)}
3. Relation as an Arrow Diagram: If P and Q are finite sets and R is a relation from P
to Q. Relation R can be represented as an arrow diagram as follows.
Draw two ellipses for the sets P and Q. Write down the elements of P and elements of Q
Example
1. Let P = {1, 2, 3, 4}
2. Q = {a, b, c, d}
3. R = {(1, a), (2, a), (3, a), (1, b), (4, b), (4, c), (4, d)
Make the table which contains rows equivalent to an element of P and columns
equivalent to the element of Q. Then place a cross (X) in the boxes which represent
relations of elements on set P to set Q.
Example
1. Let P = {1, 2, 3, 4}
2. Q = {x, y, z, k}
3. R = {(1, x), (1, y), (2, z), (3, z), (4, k)}.
Composition of Relations
Let A, B, and C be sets, and let R be a relation from A to B and let S be a relation from B
to C. That is, R is a subset of A × B and S is a subset of B × C. Then R and S give rise to a
relation from A to C indicated by R◦S and defined by:
Let R is a relation on a set A, that is, R is a relation from a set A to itself. Then R◦R, the
composition of R with itself, is always represented. Also, R◦R is sometimes denoted by
R2. Similarly, R3 = R2◦R = R◦R◦R, and so on. Thus Rn is defined for all positive n.
Example1: Let X = {4, 5, 6}, Y = {a, b, c} and Z = {l, m, n}. Consider the relation
R1 from X to Y and R2 from Y to Z.
R1 = {(4, a), (4, b), (5, c), (6, a), (6, c)}
R2 = {(a, l), (a, n), (b, l), (b, m), (c, l), (c, m), (c, n)}
Solution:
R1 o R2 = {(4, l), (4, n), (4, m), (5, l), (5, m), (5, n), (6, l), (6, m), (6, n)}
There is another way of finding R◦S. Let M R and MS denote respectively the matrix
representations of the relations R and S. Then
Example
(i) To obtain the composition of relation R and S. First multiply M R with MS to obtain the
matrix MR x MS as shown in fig:
The non zero entries in the matrix MR x MS tells the elements related in RoS. So,
Hence the composition R o S of the relation R and S is
1. R o S = {(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (4, 2), (4, 5), (5, 2), (5, 3), (5, 4), (5, 5)}
.
1. R o R = {(2, 2), (3, 2), (3, 3), (3, 4), (4, 2), (4, 5), (5, 2), (5, 3), (5, 5)}
(iii) Multiply the matrix MS with MR to obtain the matrix MS x MR as shown in fig:
1. S o R = {(2, 4) , (2, 5), (3, 3), (3, 4), (3, 5), (4, 2), (4, 4), (4, 5), (5, 2), (5, 3), (5, 4),
(5, 5)}.
Closure Properties of Relations
Consider a given set A, and the collection of all relations on A. Let P be a property of such
relations, such as being symmetric or being transitive. A relation with property P will be
called a P-relation. The P-closure of an arbitrary relation R on A, indicated P (R), is a P-
relation such that
1. R ⊆ P (R) ⊆ S
(1) Reflexive and Symmetric Closures: The next theorem tells us how to obtain the
reflexive and symmetric closures of a relation easily.
Example1:
RF = R ∪ ∆ = {(k, k), (k, l), (l, l), (l, m), (m, m), (m, k)}.
1. R = {(4, 5), (5, 5), (5, 6), (6, 7), (7, 4), (7, 7)}
Solution: The smallest relation containing R having the symmetric property is R ∪ R-1,i.e.
RS = R ∪ R-1 = {(4, 5), (5, 4), (5, 5), (5, 6), (6, 5), (6, 7), (7, 6), (7,
4), (4, 7), (7, 7)}.
Example1: Consider the relation R = {(1, 2), (2, 3), (3, 3)} on A = {1, 2, 3}. Then
R2 = R◦ R = {(1, 3), (2, 3), (3, 3)} and R 3 = R2 ◦ R = {(1, 3), (2, 3), (3, 3)} Accordingly,
Transitive (R) = {(1, 2), (2, 3), (3, 3), (1, 3)}
Example2: Let A = {4, 6, 8, 10} and R = {(4, 4), (4, 10), (6, 6), (6, 8), (8, 10)} is a
relation on set A. Determine transitive closure of R.
Hence, the transitive closure of M R is MR* as shown in Fig (where MR* is the ORing of a
power of MR).
Thus, R* = {(4, 4), (4, 10), (6, 8), (6, 6), (6, 10), (8, 10)}
Equivalence Relations
Example: Let A = {1, 2, 3, 4} and R = {(1, 1), (1, 3), (2, 2), (2, 4), (3, 1), (3, 3), (4, 2),
(4, 4)}.
Solution:
Reflexive: Relation R is reflexive as (1, 1), (2, 2), (3, 3) and (4, 4) ∈ R.
Transitive: Relation R is transitive because whenever (a, b) and (b, c) belongs to R, (a,
c) also belongs to R.
Note1: If R1and R2 are equivalence relation then R1∩ R2 is also an equivalence relation.
Example: A = {1, 2, 3}
R1 = {(1, 1), (2, 2), (3, 3), (1, 2), (2, 1)}
R2 = {(1, 1), (2, 2), (3, 3), (2, 3), (3, 2)}
R1∩ R2 = {(1, 1), (2, 2), (3, 3)}
Note2: If R1and R2 are equivalence relation then R1∪ R2 may or may not be an equivalence
relation.
Example: A = {1, 2, 3}
R1 = {(1, 1), (2, 2), (3, 3), (1, 2), (2, 1)}
R1∪ R2= {(1, 1), (2, 2), (3, 3), (1, 2), (2, 1), (2, 3), (3, 2)}
R2 = {(1, 1), (2, 2), (3, 3), (2, 3), (3, 2)}
Hence, Reflexive or Symmetric are Equivalence Relation but transitive may or may not
be an equivalence relation.
Inverse Relation
Let R be any relation from set A to set B. The inverse of R denoted by R -1 is the relations
from B to A which consist of those ordered pairs which when reversed belong to R that is:
Example1: A = {1, 2, 3}
B = {x, y, z}
Example2: R = {(1, 1), (2, 2), (3, 3), (1, 2), (2, 3), (3, 2)}
R-1 = {(1, 1), (2, 2), (3, 3), (2, 1), (3, 2), (2, 3)}
A relation R on a set A is called a partial order relation if it satisfies the following three
properties:
Example1: Show whether the relation (x, y) ∈ R, if, x ≥ y defined on the set of +ve
integers is a partial order relation.
Solution: Consider the set A = {1, 2, 3, 4} containing four +ve integers. Find the
relation for this set such as R = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3), (1, 1), (2, 2), (3,
3), (4, 4)}.
Reflexive: The relation is reflexive as for every a ∈ A. (a, a) ∈ R, i.e. (1, 1), (2, 2), (3, 3),
(4, 4) ∈ R.
45.5M
850
Transitive: The relation is transitive as whenever (a, b) and (b, c) ∈ R, we have (a, c) ∈
R.
Example2: Show that the relation 'Divides' defined on N is a partial order relation.
Solution:
Antisymmetric: Let a, b, c ∈N, such that a divides b. It implies b divides a iff a = b. So,
the relation is antisymmetric.
Then a divides c. Hence the relation is transitive. Thus, the relation being reflexive,
antisymmetric and transitive, the relation 'divides' is a partial order relation.
Example3: (a) The relation ⊆ of a set of inclusion is a partial ordering or any collection
of sets since set inclusion has three desired properties:
2. If A ⊆ B and B ⊆ A then B = A.
3. If A ⊆ B and B ⊆ C then A ⊆ C
(b) The relation ≤ on the set R of real no that is Reflexive, Antisymmetric and transitive.
n-Ary Relations
By an n-ary relation, we mean a set of ordered n-tuples. For any set S, a subset of the
product set Sn is called an n-ary relation on S. In particular, a subset of S 3 is called a
ternary relation on S.
The set A together with a partial order relation R on the set A and is denoted by (A, R) is
called a partial orders set or POSET.
Total Order Relation
Consider the relation R on the set A. If it is also called the case that for all, a, b ∈ A, we
have either (a, b) ∈ R or (b, a) ∈ R or a = b, then the relation R is known total order
relation on set A.
Example: Show that the relation '<' (less than) defined on N, the set of +ve integers is
neither an equivalence relation nor partially ordered relation but is a total order relation.
Solution:
∈
⟹ '<' is not reflexive.
Reflexive: Let a N, then a < a
As, the relation '<' (less than) is not reflexive, it is neither an equivalence relation nor the
partial order relation.
But, as ∀ a, b ∈ N, we have either a < b or b < a or a = b. So, the relation is a total order
relation.
Equivalence Class
Circular Relation
Consider a binary relation R on a set A. Relation R is called circular if (a, b) ∈ R and (b, c)
∈ R implies (c, a) ∈ R.
Solution: Reflexive: As, the relation, R is an equivalence relation. So, reflexivity is the
property of an equivalence relation. Hence, R is reflexive.
∈ ∈
⇒ (a, c) ∈
Circular: Let (a, b) R and (b, c) R
⇒ (c, a) ∈ R
R (∵ R is transitive)
(∵ R is symmetric)
Thus, R is Circular.
Compatible Relation
Friend Friend
a → b, b→c but possible that a and c are not friends.
Functions
Domain of a Function: Let f be a function from P to Q. The set P is called the domain of
the function f.
Range of a Function: The range of a function is the set of picture of its domain. In
other words, we can say it is a subset of its co-domain. It is denoted as f (domain).
1. Let x = {1, 2, 3, 4}
2. y = {a, b, c, d, e}
3. f = {(1, b), (2, a), (3, d), (4, c)
Solution:
If P and Q are two non-empty sets, then a function f from P to Q is a subset of P x Q, with
two important restrictions
Note1: There may be some elements of the Q which are not related to any element of set P.
2. Every element of P must be related with at least one element of Q.
Example1: If a set A has n elements, how many functions are there from A to A?
Representation of a Function
The two sets P and Q are represented by two circles. The function f: P → Q is represented
by a collection of arrows joining the points which represent the elements of P and
corresponds elements of Q
Example1:
e. d = {(x, 1), (y, 2), (y, 3), (z, 4), (z, 4)}.
Solution:
2. It is not a function because every element of X does not relate with some element
of Y i.e., Z is not related with any element of Y.
3. h is not a function because h (x) = {1, 2, 3, 4} i.e., element x has more than one
image in set Y.
4. d is not a function because d (y) = {2, 3} i.e., element y has more than image in
set Y.
Types of Functions
Example: Consider, A = {1, 2, 3, 4}, B = {a, b, c} and f = {(1, b), (2, a), (3, c), (4, c)}.
32.1M
593
History of Java
1. Consider P = {x, y, z}
2. Q = {a, b, c}
3. and f: P → Q such that
4. f = {(x, a), (y, b), (z, c)}
Example:
1. Consider, A = {a, b, c}
2. B = {1, 2, 3, 4} and f: A → B such that
3. f = {(a, 1), (b, 2), (c, 3)}
4. In the function f, the range i.e., {1, 2, 3} ≠ co-domain of Y i.e., {1, 2, 3, 4}
Example:
1. Consider, X = {k, l, m}
2. Y = {1, 2, 3, 4} and f: X → Y such that
3. f = {(k, 1), (l, 3), (m, 4)}
Example:
1. Consider X = {1, 2, 3, 4, 5}
2. Y = {x, y, z} and f: X → Y such that
3. f = {(1, x), (2, x), (3, x), (4, y), (5, z)}
Example:
1. Consider X = {a, b, c}
2. Y = {1, 2} and f: X → Y such that
3. f = {(a, 1), (b, 1), (c, 1)}
Example:
1. Consider X = {1, 2, 3, 4}
2. Y = {k, l} and f: X → Y such that
3. f = {(1, k), (2, k), (3, l), (4, l)}
The function f is a many-one (as the two elements have the same image in Y) and it is
onto (as every element of Y is the image of some element X). So, it is many-one onto
function
Identity Functions
It is denoted by I.
Example:
The function f is an identity function as each element of A is mapped onto itself. The
function f is a one-one and onto
32.1M
593
History of Java
Invertible (Inverse) Functions
Consider the bijective (one to one onto) function f: X → Y. As f is a one to one, therefore,
each element of X corresponds to a distinct element of Y. As f is onto, there is no element
of Y which is not the image of any element of X, i.e., range = co-domain Y.
Example:
1. Consider, X = {1, 2, 3}
2. Y = {k, l, m} and f: X→Y such that
3. f = {(1, k), (2, m), (3, l)
To find the composition of f and g, first find the image of x under f and then find the
image of f (x) under g.
Example1:
1. Let X = {1, 2, 3}
2. Y = {a, b}
3. Z = {5, 6, 7}.
Consider the function f = {(1, a), (2, a), (3, b)} and g = {(a, 5), (b, 7)} as in figure. Find
the composition of gof.
Solution:
Note:
o If f and g are one-to-one, then the function (gof) (gof) is also one-to-one.
o If f and g are onto then the function (gof) (gof) is also onto.
Mathematical Functions
The following are the functions which are widely used in computer science.
1. Floor Functions: The floor function for any real number x is defined as f (x) is the
greatest integer 1 less than or equal to x. It is denoted by [x].
Solution:
(i)[3 . 5] = 3
(ii) [-2 .4] = -3
(iii) [3. 143] = 3
2. Ceiling Functions: The ceiling function for any real number x is defined as h (x) is
the smallest integer greater than or equal to x. It is denoted by [x].
Solution:
(i)[3. 5] = 4
(ii) [-2 .4] = -2
(iii) [3. 143] = 4.
Solution:
(i) 35 (MOD 7) = 0
(ii) 20 (MOD 3) = 2
(iii) 4 (MOD 9) = 4
4. Exponential Functions: Consider two sets A and B. Let A = B = I + and also let f: A →
B be defined by f (n) = kn. Here n is a +ve integer. The function f is called the base k
exponential function.
2: k0=1,k-M=
Solution:
3-5=
5. Logarithmic Functions: Consider two sets A and B. Let A = B = R (the set of real
numbers and also let f_n:A→B be defined for each positive integer n > 1 as f n (x)=logn(x)
the base n of x.
Note1: k = logn x and nk are equivalent.
2. For any base n, logn 1=0 as n0=1.
3. For any base n, logn n=1 as n1=n.
Solution:
(i)log216 = 4 as 24=16.
(ii)log2 100 = 6 as 26= 64 but 27=128 which is greater
Characteristics of Algorithms:
1. Input: The algorithm receives input. Zero or more quantities are externally
supplied.
3. Precision: The steps are precisely stated. Each instruction is clear and
unambiguous.
The Analysis of an algorithm refers to the process of deriving estimates for the time and
space needed to execute the algorithm.
It is important to estimate the time (e.g., the number of steps) and space (e.g., the
number of variables) required by algorithms. Knowing the time and space required by
algorithm allows us to compare the algorithms that solve the same problem. For
example, if one algorithm takes n steps to solve a problem and another algorithm takes
n^2 steps to solve the same problem, we would prefer the first algorithm. This
estimation of time and space needed to execute the algorithm is called the time and
space complexity of the algorithm.
o Average case: f (n) represent by the average number of steps taken on any
instance of size n.
Asymptotic Notations
Asymptotic Notations are used to describe the execution time of an algorithm. The
notations show the order of growth of functions. Here the time taken by an algorithm is
mapped regarding mathematical functions. There are many asymptotic notations like 0,
θ, Ω,w each having its importance.
1. Big-oh notation: The function f (n) =O (g (n)) [read as "f of n is big-oh of g of n"] if
and only if exist positive constant c and n0 such that
2. Omega (Ω) Notation: The function f (n) = Ω (g (n)) [read as "f of n is omega of g of
n"] if and only if there exists positive constant c and n 0 such that
Example2: The function 20n2+ 5n +2 = Ω (n) as 20n2+ 5n +2 ≥ 20n2 for all n ≥1.
3. Theta (θ): The function f (n) = θ (g (n)) [read as "f is the theta of g of n"] if and only if
there exists positive constant k1, k2 and k0 such that
Example2: The function 20n2+ 5n +2 = θ (n2) as 20n2+ 5n +2 ≤ 21n2 for all n ≥1 and
20n2+ 5n +2 ≥ 20n2 for all n ≥ 1.
Counting Techniques
Basic Counting Principles
Sum Rule Principle: Assume some event E can occur in m ways and a second event F
can occur in n ways, and suppose both events cannot occur simultaneously. Then E or F
can occur in m + n ways.
In general, if there are n events and no two events occurs in same time then the event
can occur in n1+n2..........n ways.
Example: If 8 male processor and 5 female processor teaching DMS then the student
can choose professor in 8+5=13 ways.
Product Rule Principle: Suppose there is an event E which can occur in m ways and,
independent of this event, there is a second event F which can occur in n ways. Then
combinations of E and F can occur in mn ways.
46.2M
932
In general, if there are n events occurring independently then all events can occur in the
order indicated as n1 x n2 x n3.........n ways.
Example: In class, there are 4 boys and 10 girls if a boy and a girl have to be chosen for
the class monitor, the students can choose class monitor in 4 x 10 = 40 ways.
Mathematical Functions:
Factorial Function: The product of the first n natural number is called factorial n. It is
denoted by n!, read "n Factorial."
Solution:
Solution: = = 10 x 9=90
Binomial Coefficients: Binomial Coefficient is represented by n Cr where r and n are
positive integer with r ≤ n is defined as follows:
Permutation:
It is denoted by P (n, r)
P (n, r) =
Theorem: Prove that the number of permutations of n things taken all at a time is n!.
Example: 4 x np3=n+1P3
Solution: 4 x
4 (n-2) = (n+1)
4n - 8 = n+1
3n = 9
n = 3.
Solution: All the numbers begin with '30.'So, we have to choose 4-digits from the
remaining 7-digits.
7P4 = =840.
Theorem: Prove that the number of different permutations of n distinct objects taken at
a time when every object is allowed to repeat any number of times is given by n r.
Proof: Assume that with n objects we have to fill r place when repetition of the object is
allowed.
Circular Permutations:
Theorem: Prove that the number of circular permutations of n different objects is (n-1)!
Combination:
A Combination is a selection of some or all, objects from a set of given objects, where the
order of the objects does not matter. The number of combinations of n objects, taken r at
a time represented by nCr or C (n, r).
As there is no matter about the order of arrangement of the objects, therefore, to every
combination of r things, there are r! arrangements i.e.,
Example: A farmer purchased 3 cows, 2 pigs, and 4 hens from a man who has 6 cows, 5
pigs, and 8 hens. Find the number m of choices that the farmer has.
The farmer can choose the cows in C (6, 3) ways, the pigs in C (5, 2) ways, and the hens
in C (8, 4) ways. Thus the number m of choices follows:
If n pigeonholes are occupied by n+1 or more pigeons, then at least one pigeonhole is
occupied by greater than one pigeon. Generalized pigeonhole principle is: - If n
pigeonholes are occupied by kn+1 or more pigeons, where k is a positive integer, then at
least one pigeonhole is occupied by k+1 or more pigeons.
Example1: Find the minimum number of students in a class to be sure that three of
them are born in the same month.
Solution: Here n = 12 months are the Pigeonholes
And k + 1 = 3
K=2
Example2: Show that at least two people must have their birthday in the same month if
13 people are assembled in a room.
Solution: We assigned each person the month of the year on which he was born. Since
there are 12 months in a year.
So, according to the pigeonhole principle, there must be at least two people assigned to
the same month.
Inclusion-Exclusion Principle:
Let A1,A2......Ar be the subset of Universal set U. Then the number m of the element which
do not appear in any subset A1,A2......Ar of U.
Example: Let U be the set of positive integer not exceeding 1000. Then |U|= 1000 Find |
S| where S is the set of such integer which is not divisible by 3, 5 or 7?
By Integer division,
|S|=1000-(333+200+142)+(66+47+28)-9
|S|=1000-675+141-9=457
Recurrence Relations
The order of the recurrence relation or difference equation is defined to be the difference
between the highest and lowest subscripts of f(x) or a r=yk.
The degree of a difference equation is defined to be the highest power of f (x) or a r=yk
Example1: The equation y3k+3+2y2k+2+2yk+1=0 has the degree 3, as the highest power of
yk is 3.
Example3: The equation yk+3 +2yk+2 +4yk+1+2yk= k(x) has the degree 1, because the
highest power of yk is 1 and its order is 3.
Example4: The equation f (x+2h) - 4f(x+h) +2f(x) = 0 has the degree1 and its order is
2.
Recurrence Relations
Example2: The Fibonacci sequence is defined by the recurrence relation a r = ar-2 + ar-1,
r≥2,with the initial conditions a0=1 and a1=1.
46.2M
932
The order of the recurrence relation or difference equation is defined to be the difference
between the highest and lowest subscripts of f(x) or a r=yk.
The degree of a difference equation is defined to be the highest power of f (x) or a r=yk
Example1: The equation y3k+3+2y2k+2+2yk+1=0 has the degree 3, as the highest power of
yk is 3.
Example3: The equation yk+3 +2yk+2 +4yk+1+2yk= k(x) has the degree 1, because the
highest power of yk is 1 and its order is 3.
Example4: The equation f (x+2h) - 4f(x+h) +2f(x) = 0 has the degree1 and its order is
2.
Where C0,C1,C2......Cn are constant and R (n) is same function of independent variable n.
A solution of a recurrence relation in any function which satisfies the given equation.
The equation is said to be linear homogeneous difference equation if and only if R (n) = 0
and it will be of order n.
The solution of the equation (i) is of the form , where ∝1 is the characteristics root
and A is constant.
The equation (iii) is called the characteristics equation of the difference equation.
To find the solution of the linear homogeneous difference equations, we have the four
cases that are discussed as follows:
Case1: If the characteristic equation has n distinct real roots∝1, ∝2, ∝3,.......∝n.
If α+iβ is the root of the characteristics equation, then α-iβ is also the root, where α and
β are real.
Thus, (α+iβ)K and (α-iβ)K are solutions of the equations. This implies
(α+iβ)K A1+α-iβ)K A2
Is also a solution to the characteristics equation, where A 1 and A2 are constants which are
to be determined.
⇒ s = 1, 2
s2-3s+2=0 or (s-1)(s-2)=0
ar=C1r+C2.2r.
9s2-6s+1=0 or (3s-1)2=0
⇒s= and
yK=(C1+C2 k).
s=
Particular Solution
(a) Homogeneous Linear Difference Equations and Particular Solution:
We can find the particular solution of the difference equation when the equation is of
homogeneous linear type by putting the values of the initial conditions in the
homogeneous solutions.
Example1: Solve the difference equation 2ar-5ar-1+2ar-2=0 and find particular solutions
such that a0=0 and a1=1.
s= and 2.
a1= C1+2C2=1...........equation.(b)
Example2: Solve the difference equation ar-4ar-1+4ar-2=0 and find particular solutions
such that a0=0 and a1=6.
Example3: Solve the difference equation 9ar-6ar-1+ar-2=0 satisfying the conditions a0=0
and a1=2.
Solution: The characteristics equation is
9s2-6s+1=0 or (3s-1)2=0
s=
ar(P)=6r. .
There are two methods to find the particular solution of a non-homogeneous linear
difference equation. These are as follows:
In this method, firstly we assume the general form of the particular solutions according to
the type of R (n) containing some unknown constant coefficients, which have to be
determined. Then according to the difference equation, we will determine the exact
solution.
The general form of a particular solution to be assumed for the special forms of R (n), to
find the exact solution is shown in the table.
Z, here z is constant A
Zr. P (r), here P(r) is a polynomial of the nth degree in r. Z is a [A0 rn+A1 rn-1+⋯..An].Zr
constant.
Example1: Find the particular solution of the difference equation a r+2-
3ar+1+2ar=Zr ........equation (i)
A= (Z≠1, Z≠2)
Now to find the value of A, put this solution on L.H.S of the equation (i), then this
becomes
= A. 5r+2-5.A5r+1+6.A5r
= 25A. 5r-25A.5r+6A.5r
r
= 6A.5 ............equation (ii)
A=
Solution: Let us assume the general form of the solution = (A0+A1r). 2^r
7A1=1 ∴ A 1=
7A0+10A1=0 ∴ A 0=
Therefore, the particular solution is
Firstly, x in the function is incremented by a constant and then former is subtracted from
the later i.e.,
∆f(x)=f(x+h)-f(x)
Proof: The operation of ∆ on f(x) is of two steps. First, increment the value of x in the
function. So, whenever, there is x in f(x) put x+h (here h is constant increment), which
means operation of E on f(x) i.e.,
f (x+h)=Ef(x).
Second, subtract the original function from the value obtained in the first step, hence
∆f(x)=Ef(x)-1f(x)=(E-1)f(x)
E ≅1+∆.
Therefore, we have
To find the particular solution of (ii) for different forms of R (n), we have the following
cases.
We know that, the operation of E on any constant will be equal to the constant itself i.e.,
EA=A
Therefore, P (E) A = (C0 Er+C1 Er-1+C2 Er-2+⋯+Cn)A
= (C0+C1+C2+⋯+Cn)A
= P (1) A
yn = ,P(1)≠0
Case2: When R (n) is of the form A. Zn, where A and Z are constants
=AP(Z).Zn
Thus, yn = , P (Z) ≠ 0
If A = 1, then yn=
All other higher terms will be zero because R (n) is a polynomial of degree m.
Case4: When R (n) is of the form R(n).Z n,where R(n) is a polynomial of degree m and Z is
some constant
Similarly, we have
ar = .12
Total Solution
If y(h) denotes the homogeneous solution of the recurrence relation and y (p) indicates the
particular solution of the recurrence relation then, the total solution or the general
solution y of the recurrence relation is given by
y =y(h)+y(p).
Solution: The homogeneous solution of this equation is obtained by putting R.H.S equal
to zero i.e.,
ar-4ar-1+4ar-2=0
Generating Functions
Let us consider, the sequence a 0, a1, a2....ar of real numbers. For some interval of real
numbers containing zero values at t is given, the function G(t) is defined by the series
G(t)= a0, a1t+a2 t2+⋯+ar tr+............equation (i)
Also,If a(1)r has the generating function G1(t) and a(2)r has the generating function G2(t),
then λ1 a(1)r+λ2 a(2)r has the generating function λ 1 G1(t)+ λ2 G2(t). Here λ1 and λ2 are
constants.
Application Areas:
By the method of generating functions with the initial conditions a 0=2 and a1=3.
Now, put a0=2 and a1=3 in equation (ii) and solving, we get
= B ∴B=1