Professional Documents
Culture Documents
Unit 1
Unit 1
Syllabus:
Sets relations equivalence relations
partial orders functions recursive functions
sequences induction principle structural
induction
recursive algorithms counting pigeonhole
principle
permutations and combinations recurrence
relations
SNSCE - CSE
Set
Definition: Set is a well
s defined collection of objects
SNSCE - CSE
Set
s
SNSCE - CSE
Set
s
SNSCE - CSE
Set
s
SNSCE - CSE
Set
s
SNSCE - CSE
Set
s
SNSCE - CSE
Set
s
SNSCE - CSE
Set
s
SNSCE - CSE
Relatio
Definition: Let A and B be sets. A binary relation
ns of AB.
from A to B is a subset
In other words, for a binary relation R we have
R AB. We use the notation aRb to denote that
(a, b)R and aRb to denote that (a, b)R.
Example: Let P be a set of people, C be a set of
cars, and D be the relation describing which
person drives which car(s).
P = {Carl, Suzanne, Peter, Carla},
C = {Mercedes, BMW, tricycle}
D = {(Carl, Mercedes), (Suzanne, Mercedes),
(Suzanne, BMW), (Peter, tricycle)}
This means that Carl drives a Mercedes, Suzanne
drives a Mercedes and a BMW, Peter drives a
tricycle, and Carla does not drive any of these
vehicles.
SNSCE - CSE
10
Relatio
ns
SNSCE - CSE
11
Relatio
ns
SNSCE - CSE
12
Equivalence
Equivalence
relations are used to relate
Relations
objects that are similar in some way.
SNSCE - CSE
13
Partial
Orders
A partial order
is a binary relation "" over a
set P which is reflexive, antisymmetric, and
transitive, i.e., which satisfies for all a, b, and c
in P:
a a (reflexivity);
if a b and b a then a = b (antisymmetry);
if a b and b c then a c (transitivity).
In other words, a partial order is an
antisymmetric preorder.
SNSCE - CSE
14
Function
s
SNSCE - CSE
15
Identity
function
A function f from a set A
to the same set A stating that
f(x) = x for all elements of x
in the set A.
Identity function is one
one and onto also.
It is a bijective mapping
from a set into it self.
SNSCE - CSE
16
One one
function
A function f from a set A
to set B such that for any
element of set B there exists
only one preimage in set A.
If f(a) = f(b) then a = b
for all elements of a,b in set
A.
It is also called as
injective or some times 1 1.
SNSCE - CSE
17
Onto
A function
function from a set A to
set B such that for all
elements of set B there exists
at least
one element in set B such
that f(a) = b.
It is also called as
surjective mapping.
Here f(A) = B.
All images are have
SNSCE - CSE
18
One to one
A function from a set A to set
function
19
Step
function
A function
f from real
20
Absolute function
A function from real numbers set
to real numbers set stating that
x if x is > 0
f(x) =
-x if x is < 0
0 if x is = 0
SNSCE - CSE
21
Recursive
A recursive function is an equation that
Functions
recursively
defines a sequence, once one or
more initial terms are given: each further term of
the sequence is defined as a function of the
preceding terms.
The term difference equation sometimes
(and for the purposes of this article) refers to a
specific type of recurrence relation. However,
"difference equation" is frequently used to refer
Example: We obtain the sequence of Fibonacci numbers which
to
any recurrence relation.
begins:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
It can be solved by methods described below yielding the closed-form
expression which involve powers of the two roots of the characteristic
polynomial t2 = t + 1; the generating function of the sequence is the
rational function
SNSCE - CSE
22
Sequenc
A sequence
esis an ordered list. Like a set, it
Induction
Principle
Mathematical
induction
is a method of
mathematical proof typically used to establish a
given statement for all natural numbers.
It is done in two steps.
The first step, known as the base case, is to
prove the given statement for the first natural
number.
The second step, known as the inductive
step, is to prove that the given statement for any
one natural number implies the given statement
for the next natural number.
From these two steps, mathematical
induction is the rule from which we infer that the
given statement is established for all natural
numbers.
SNSCE - CSE
24
Structural
Structural induction is a proof method that is used in
Induction
mathematical
logic (e.g., in the proof of o' theorem), computer
25
Recursive
Algorithms
The Nature of Recursion Algorithms
Problems that lend themselves to a recursive solution have the
following characteristics: One or more simple cases of the problem
(called stopping cases) have a simple, non-recursive solution.
For the other cases, there is a process (using recursion) for substituting
one or more reduced cases of the problem that are closer to a stopping
case.
Eventually the problem can be reduced to stopping cases only, all of
which are relatively easy to solve.
if (the stopping case is
reached)
{
Solve it
}
else
{
Reduce the problem
using recursion
}
SNSCE - CSE
26
Recursive
To Algorithms
find N!: If N = 1 then N!
1.
N! = N x (N - 1)!
= 1; Otherwise
3.
27
Counting
Pigeonhole
Pigeonhole principle : If n items are put into m
Principle
pigeonholes
with n > m, then at least one
pigeonhole must contain more than one item. This
theorem is exemplified in real-life by truisms like
"there must be at least two left gloves or two right
gloves in a group of three gloves".
It is an example of a
counting argument, and
despite seeming intuitive
it can be used to demonstrate
possibly unexpected results;
for example, that two people in
London have the same
number of hairs on their heads
SNSCE - CSE
29
Permutations and
Combinations
Permutation means to the act of permuting
(rearranging) objects or values. Informally, a
permutation of a set of objects is an arrangement of
those objects into a particular order.
example, there are six permutations of the set
{1,2,3}, namely (1,2,3), (1,3,2), (2,1,3), (2,3,1),
(3,1,2), and (3,2,1).
The number of permutations of n distinct
objects is "n factorial" usually written as "n!", which
means the product of all positive integers less than or
equal to n.
SNSCE - CSE
30
Permutations and
Combinations
A permutation of a set S of objects is an ordered
arrangement of these objects.
The number of r-permutations of a set with n
elements is denoted by P n r
Example:
How many permutations of the letter JKLMNOPQ contain
the string JKL?
Since the letter JKL must occur in a block, we must consider
six objects namely JKL as one block and M,N,O,P,Q. the six
objects can occur in any order and there are 6! = 720
permutations of the letters JKLMNOPQ in which JKL occurs
as a block
SNSCE - CSE
31
Permutations and
Combinatio
Combinations
ns
32
Permutations and
Combination is a way of selecting several
Combinations
things
out of a larger group, where (unlike
permutations) order does not matter. In smaller
cases it is possible to count the number of
combinations.
For example given three fruits, say an apple,
an orange and a pear, there are three combinations
of two that can be drawn from this set: an apple and
a pear; an apple and an orange; or a pear and an
orange.
More formally a k-combination of a set S is a
subset of k distinct elements of S. If the set has n
elements the number of k-combinations is equal to
the binomial coefficient
SNSCE - CSE
33
Recurrence
Relations
SNSCE - CSE
34
Recurrence
Recurrence relations are having
Relations
fundamental
importance in Analysis of
Algorithms. If an algorithm is designed so that
it will break a problem into smaller sub
problems, its running time is described by a
recurrence relation.
A simple example is the time an
algorithm takes to search an element in an
ordered vector with n elements, in the worst
case.
A naive algorithm will search from left to
right, one element at a time. The worst
possible scenario is when the required element
is the last, so theSNSCE
number
of comparisons is n.
- CSE
35
Recurrence
A better algorithm is called binary search. It
Relations
will first
check if the element is at the middle of
the vector.
SNSCE - CSE
36