Professional Documents
Culture Documents
Mathematical Preliminaries
Topics
• Set Theory
• Combinatorics
• Mathematical Functions
• Summations
• Probability Theory
Set Theory
Set Theory
Definitions
A Set is a collection of objects called members. If a, b, c, d are members of a set S we write :
S ={a, b, c, d}
In a set all members are distinct objects , i. e, duplicate members are not allowed
A ⊆ B, if x ∈A then x ∈B
The set A is proper subset of B, if A contains only some of the elements of B. Symbolically
the relationship is represented as:
A ⊂ B
The relationship among sets is usually shown by a picture, which is called Venn diagram.
Figures (a), (b) show Venn diagrams for a subset and proper subset
B
A=B
A
A ⊂ B A ⊆ B
(a) A is proper subset of B (b) A is subset of B
Set Theory
Universal Set
The largest set for a given collection of objects is called Universal Set. All other sets are
subsets of the Universal set U. Symbolically:
φ ⊆ U, A ⊆ U, B⊆ U, C ⊆ U
A B
C
A B A U B
Union set
Example (1): A={ 1, 3, 4, 5}, B={ 3, 4, 7, 8, 9}. The Union of sets A and B is the
set { 1, 3, 4, 5, 7,8, 9}.
Example(2): Union operation can be used to add elements to a set. Consider sets {a, b}, {c, d}
(i) Setting S to empty set φ
S=φ
(ii) To insert elements of first set into S, we perform union of S with {a, b}
S = S U {a, b} = {a, b}
(iii) To insert elements of second set {b, c} into S, we perform union of S with {c, d}
S = S U {c, d} = {a, b, c, d}
Set Operations
Intersection
The intersection of set A and set B is set of all elements x, such that x is in A and
x is in B. Symbolically:
A I B, if x ∈A and x ∈B
The intersection operation is pictorially represented by Venn Diagram, as shown below.
A B A I B
Set intersection
Two sets are called disjoint, if their intersection is empty set. Thus, if A and B are disjoint,
A I B=φ
Set Operations
Difference Set
The difference of set A and set B is set of all elements x, such that x is not in B if x is in A.
Symbolically:
B – A , if x ∈A then x ∉B
The difference operation is illustrated by Venn Diagram, as shown below.
A B B-A
Difference set
(ii) To delete element d we perform difference operation on set S and set {d}.
S = S-{d} = { b, c, e, f }
Set Theory
Cardinality
The cardinality of a set is the number of elements in the set. It is also called size. The
cardinality of set S is denoted by |S| .
A U B = {a, b, c, d, e, f, g, h, i, j, k}, | A U B | = 11
It follows that | A | + | B | - | A ∩ B | = 6 + 8 – 3 = 11
Set Theory
Cartesian Product
The Cartesian product of two sets A and B, denoted by A X B, is a set of all
ordered pairs such that the first element of the pair is in set A and the second element
is in set B. It is also called cross product. Mathematically,
A X B = { (a , b) : a ∈A and b∈ B }
A X B = {(a, g), (a, h), (b, g), (b, h), (c, g), (c, h) }
| A X B | = | A | .| B |
Set Theory
Binary Relation
A binary relation R on sets A and B is a subset of the Cartesian product A X B of the sets .
In set notation, the relation is represented as:
R ⊆ AXB
Since a cross product set can have one or more subsets there can be many binary relations
Their cross product is set A X B = {(a, x), (a, y), (b, x), (b, y), (c, x), (c, y) }
Example: Consider the graph G = (V, E) , and V = { a, b, c }, vertex set for the graph
A binary relation is
The set E represents edges of graph G. The graph is shown pictorially in the diagram below.
Combinatorics
Permutations
Definition
A permutation is an arrangement of n objects in some order, such that each object appears
exactly once.
Example: The elements of Set S={ a, b, c } can be permuted in six ways because
3! = 3.2.1 = 6
The six arrangements are: abc, acb, bac, bca, cab, cba
n n!
2 2
4 24
8 40,320
16 20,922,789,888,000
32 2.6 x 10 35
¾ The analysis of algorithms sometimes involves large inputs. For large values of n, the
n! is approximated by the following formula,:
n! ≈ √ ( 2 π n ) ( n / e) n , where e = 2.718
v. y = x2 (Quadratic function)
y= └x ┘
where x is a real number and y is the largest integer which is smaller than or equal to
number x.
Example: └ 4.9┘= 4,
└ 4.0 ┘ = 4
It follows from the definition : x -1 <└ x ┘ ≤ x
¾ The floor function is used for mapping of a real valued function into integer function
Ceil Function
Definition
y= ┌x ┐
where x is real number and y is the smallest integer larger than or equal to x.
Example: ┌ 4.9 ┐= 5
┌ 4.0 ┐ = 4
¾ The ceil function is used for mapping a real valued functions into integer function
Logarithm Function
Definition
The logarithm function y= log a x is the inverse of exponential function ay, where a is some
positive constant.
Thus, if y = log a x ,
then
x=ay
Example: Consider, y= log 5 25 . Since 25= 52, it follows y=2 .
¾ The base 10 is normally used in computations involving decimal numbers. Here are some
examples
log 10 1 =0 because 1= 10 0 by definition
log 10 10 =1 10= 10 1
log 10 100 = 2 100=10 2
log 10 1000000 = 6 1000000=10 6
¾ The base 2 is often used in the analysis of algorithms. Some examples of base 2 are
log 2 1=0 because 1= 20 by definition
log 2 2= 1 2=21
log 2 16= 4 16= 24
log 2 64= 6 64= 26
The logarithm to base 2 are referred to as binary logarithm. A special notation lg is used
to represent a binary algorithm, as follows
lg (n) ≡ log 2 (n)
¾ The base e ≈ 2.718 is used in calculus for purposes of differentiation and integration It is
called natural logarithm. A special notation ln is used to represent natural logarithms.
ln (n) ≡ log e (n)
Logarithm Function
Properties
The following properties of logarithms are often used in several applications
• log b x . y = logb x + logb y (Sum rule)
¾ The last property is particularly useful for interchanging logarithmic exponential and
base of exponentiation. Here are some examples.
lg x = log2 x
= log e x / loge2
= ln x / ln 2 ( ln 2 = 0.6931)
Mathematical Functions
Growth Rates
The table shows the growth rate of common mathematical functions, which are useful in the
analysis of algorithms
n lg n √n n lg n n2 n3 2n n! nn
2 1 1.4 2 4 8 4 2 2
4 2 2 8 16 64 16 24 256
¾ The logarithm lg n has the lowest growth rate , and the exponential function n n
the highest
¾ The relationship of functions in terms of their growth rates is symbolically represented as
lg n < √n < n < n lgn < n2 < n3 < 2n < n! < n n
Growth Functions
Graph
The plot of mathematical functions lg n, n, n lg n n2, n3, 2n is shown below.
f(n)
¾ Because of extremely rapid growth of n! and nn , these functions are not shown in the
ranges shown in the graph scale
Summations
Summation
Arithmetic
Thenarithmetic summation consist of sum natural numbers (1, 2, 3….n)
∑k
k =1
= 1 + 2 + 3+………..+ n = n ( n+1 ) / 2
Thus, S = n ( n + 1) / 2
Another summation sometimes used in analysis is sum of squares of natural numbers. It has
the sum:
S= 12 + 22 + 32+ ……+n2 = n(n+1)(2n+1)/6
Summation
Geometric
The geometric summation consists of sum of powers of some fixed number.
The fixed number is referred to as geometric ratio. Hers is a common form of exponential
summation:
n
∑r
k
= r 0 + r 1+ r 2 + ……..+ r n-1 +r n = ( rn+1 - 1) / (r - 1)
k =0
where r is the geometric ratio.
¾ The summation is evaluated as follows. Let S be the sum of first n terms of the series. Then,
S = r 0 + r 1 + r 2+r3 ……..+ r n-1 + r n ………….(1)
Multiplying both sides of (1) with r
r .S = r 1 + r 2+r 3+ … +rn-1 + rn +r n+1 …………..(2)
Subtracting (1) from (2)
(r-1).S = rn+1-r0
= rn+1 -1
Or S = (rn+1-1) / ( r -1) …………(3)
∑ km
k
= 1.m1 + 2.m2 + 3.m3+ …….+ n.mn
k =0
The following summation of arithogeomatric series, with base 2, arises in the analysis of
some algorithms.
n k
∑ k.2 = 1.21 + 2.22 + 3.23+ …….+ n.2n = (n-1) 2n+1 + 2
k =0
Summation
Harmonic
The harmonic summation consists of reciprocals of natural numbers (1,2,…..n).
n
∑1 / k
k =1
= 1/1 + 1/2 + 1/3 +…….+1/n ≈ ln n + γ + 1 / 2n - 1 / 12n
¾ The Harmonic series does not have an exact formula for the sum . The approximate
sum is obtained by converting the summation into an integral
¾ By using mathematical analysis it can be shown that upper and lower bounds of
harmonic series are given by the relation
n
ln(n+1) ≤ ∑ 1 / k ≤ 1 + ln(n)
k =1
Summation
Logarithmic
The logarithmic summation includes logarithms of natural numbers (1,2,…,n ). Assuming
base 2 for the logarithm, the series is expressed as follows:
n
∑ lg(k )
k =1
= lg(1) + lg(2) + lg(3)+……..+lg(n) . = lg(1.2.3..n) =lg( n! )
An estimate for the above summation is obtained, by using the Stirling ‘s approximation
for large factorial. Since n! ≈ √ ( 2 π n ) ( n / e) n where e = 2.718, it
follows that
lg n! ≈ n lg( n) ( ignoring lower order terms and constants)
Therefore, the approximate summation for logarithm series for large n is given by :
The set of all possible outcomes of an experiment are called sample space or population..
Let e1, e2, e3, …… en are the probable n outcomes of an experiment. Then the sample space
is the set Ω = { e1, e2, e3, …… en }
Sample Space
Examples
Example (1): A fair coin is tossed. The result can be Head( H ) or Tail( T ). The sample
space for the tossing experiment is:
Ω = {H, T}.
Example (2) : A fair coin is tossed twice ( or two coins are tossed simultaneously) the sample
space for the toss is:
Ω = { HH, HT, TH, TT}
Example (3): A six-faced die is thrown. The sample space for the event is
Ω = {1, 2, 3, 4, 5, 6 }
. where digits represent number of dots on each face of the die.
Example(4): Two six-faced dice are tossed. The sample space consists of 36 pairs of
integers:
Ω={(1,1),(1,2)(1,3),(1,4),(1,5), (1,6), (2,1),(2,2)(2,3,),(2,4),(2,5), (2,6),
(3,1),(3,2)(3,3),(3,4),(3,5), (3,6), (4,1),(4,2)(4,3,),(4,4),(4,5), (4,6),
(5,1),(5,2)(5,3),(5,4),(5,5), (5,6), (6,1),(6,2)(6,3),(6,4),(6,5), (6,6) }
E ⊆ Ω
¾ A six-faced die is thrown. The sample space Ω consists of all numbers that are likely to
be shown i. e,
Ω ={1, 2, 3, 4, 5, 6 }
¾ The probabilities are generally assigned on the basis of experience or judgment. Some
times the probabilities are expressed as percentages, or in terms frequencies of happening of
different events.
Example(1): Chance that a flight will be on time is 90% and would be late is 10% . Thus,
P(on time)= 90/100=0.9 and P(late)=10/100=0.1
Example(2): Based on experience, we say that chance of finding a document on Yahoo is twice that of
finding on MSN, and four times on Google. If p is probability of finding the document on MSN then,
we have :P (msn ) = p ; P(yahoo ) = 2p ; P(google) ) = 4p
By probability axiom , p + 2p + 4p =1 or p=1/7
Thus, we have P(msn)= 1 / 7, P(yahoo)= 2 / 7, and P(google)=4 / 7
Probability Theory
Equiprobable Events
In several cases the probabilities are not known, but it is expected that all events are equally
likely to occur . Therefore, all the elementary events are assigned equal probabilities.
Since by definition
P(e1)+P(e2)+P(e3)+…+P(en)=1
it follows that
Example (2) When six-faced die is thrown, all numbers, 1 to 6, have equal chance of being
shown. Therefore, each event has probability 1/6. Thus, probabilities of showing different
numbers are
. P(1)=1/6, P(2)=1/6, P(3)=1/6, P(4)=1/6, P(5)=1/6, P(6)=1/6
Example(3): An array stores n random keys. Assuming that a search key has equal chance
of being in any of the array cells, the probability of finding the key in a given cell is 1/n
Example(4): A six-faced die is tossed. The event set that a odd number is shown consists of
the elements 1, 3, 5. The probability that an odd number would be displayed is 3/6=1/2
Probability Theory
Law of Addition
Two events A, B are said to be mutually exclusive provided that if A occurs then B cannot
occur; conversely, if B occurs then A cannot occur. For example, if a six-faced die is tossed
then showing of 1 and 6 are mutually exclusive events because if 1 is shown then 6 will not be
shown and vice versa.
According to Law of Addition of Probabilities, If A and B are two mutually exclusive
events with probabilities P(A) and P(B) ,then probability that A occurs OR B occurs is given
by the sum of probabilities P(A) + P(B). Simply stated ,
In general, if A1, A2, A3…Ak are mutually exclusive events then
For example, if a coin is tossed several times the result of previous toss does affect the
result of current toss, and result of current toss would not influence the result of next toss.
We can say that the events of successive tossing are stochastically independent events.
P( A AND B) = P(A).P(B)
In general, if A1, A2, A3, .Ak are stochastically independent events then
Example(2): A six faced die is tossed three times. What is probability that three sixes would
be shown or three fives would be shown consecutively.
In each toss the probability of showing 5 or 6 is 1/6.
(1)According multiplication law, the probability of showing three consecutive sixes is
P(6 AND 6 AND 6) =(1/6).(1/6).(1/6)= 1/216
(2) Again according to law of multiplication, the probability of showing three fives
P(5 AND 5 AND 5) =(1/6) .(1/6). (1/6)=1/216
(3) According to law of addition , the probability that 6 is shown three times OR 5 is shown
three times, is obtained by adding the above probabilities
P( (6 AND 6 AND 6) OR ( 5 AND 5 AND 5 ) )= P ( 6 AND 6 AND 6) + P(5 AND 5 AND 5)
=1/216 + 1/216 = 1/108
Probability Theory
Expected Cost
Let c1, c2, …..cn be the costs associated with events e1, e2, …en . Let the probabilities for
the occurrence of events be P(e1), P(e2)…..P(en) , then the expected cost (EC) is defined as
Example: Suppose a coin is tossed 2 times. Assume that the costs associated with events
are :
if two heads appear cost is 2
if one head appears cost is 1
if no heads appear (equivalently only tails show) cost is 0
• The event space S for the experiment is Ω = { HH, HT, TH, TT}
Probability that event HH occurs = 1/2.1/2= 1/4
Probability that event HT occurs =1/2.1/2=1/4
Probability that event TH occurs = 1/2.1/2=1/4 By law of multiplication
Probability that event TT occurs =1/2.1/2=1/4
• The four events have associated costs of 2, 1,1, 0 with probabilities 1/4, 1/4. 1/4, 1/4.
Thus, the expected cost of the tossing experiment = 2.(1/4) + 1.(1/4) + 1.(1/4) + 0.(1/4)
= 1/ 2 + 1/ 4 + 1/ 4 = 1
Searching an Array
Expected Cost
Consider the problem of performing linear search on an array of size n .
It is assumed that the search key has equal probability of being found in any
of the n array cells. Thus, the probability that key is in any of the n cells is 1/n
Assuming that unit cost of searching one cell of the array is c, the probabilities and the
costs associated with search operation up to each cell are summarized in the table