unit ii discrete structures relations and functions se (comp.engg.)
Post on 18-Jan-2016
217 Views
Preview:
TRANSCRIPT
Unit II Discrete Structures
Relations and Functions
SE (Comp.Engg.)
Cartesian productsThe Cartesian product of set A and set B is denoted by AB and equals {(a, b)aA and bB}. The elements of AB are ordered pairs. The elements of A1A2…An are ordered n-tuples.AB=AB
• Ex . A={2, 3, 4}, B={4, 5} , C={x,y}• A B ={<2,4>,<2,5>,<3,4>,<3,5>,<4,4>,<4,5>}
Tree diagrams for the Cartesian product
Relations
• Any subsets of AB is called a binary relation from A to B. Any subset of AA is called a binary relation on A.
For finite sets A and B with A=m and B=n, there are 2mn relations from A to B.
• Example: Let A = {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b) | a < b} ?
• Solution: R = {
• Domain= set of first elements in the caresian product .• Range= set of second elements in the caresian product .
Domain={1,2,3}Range={2,3,4}
(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}
• Converse of a Relation A is given by the relation à such that the elements in the ordered pairs in A are interchanged.
• i.e if xAy then y à x.
Matrix Representation of a Relation
• MR = [mij] (where i=row, j=col) mij={1 iff (i,j) R and 0 iff (i,j) R}
• Ex: R : {1,2,3}{1,2} where x > y – R = {(2,1),(3,1),(3,2)}
100
110
321
21
RM
Graph Representation of a Relation
Properties of Relations
• A relation R on a set A is called reflexive if (a, a)R for every element aA.
• A relation on a set A is called irreflexive if (a, a)R for every element aA.
•A relation R on a set A is called symmetric if (b, a)R whenever (a, b)R for all a, bA.
•A relation R on a set A is called antisymmetric if
a = b whenever (a, b)R and (b, a)R.
•A relation R on a set A is called asymmetric if (a, b)R implies that (b, a)R for all a,bA.
• A relation R on a set A is called transitive if whenever (a, b)R and (b, c)R, then (a, c)R for a, b, cA.
• A={1,2,3,4,5,6,7,8,9}• Give examples of relation R, such that,I. R is not reflexive and not irreflexive.II. R is symmetric as well as antisymmetric.III. R is transitive but not symmetric and not
reflexive.IV. R is transitive, reflexive but not symmetric.
Equivalence Relations
• Any binary relation that is:ReflexiveSymmetricTransitive
Equivalence Classes
•Let R be an equivalence relation on a set A. The set of all elements that are related to an element a of A is called the equivalence class of a. •The equivalence class of a with respect to R is denoted by [a]R.
•If b[a]R, b is called a representative of this equivalence class.
Partition
•A partition of a set S is a collection of disjoint nonempty subsets of S that have S as their union. In other words, the collection of subsets Ai, iI, forms a partition of S if and only if (i) Ai for iI
• Ai Aj = , if i j
• iI Ai = S
• Let R be an equivalence relation on a set S. Then the equivalence classes of R form a partition of S. Conversely, given a partition {Ai | iI} of the set S, there is an equivalence relation R that has the sets Ai, iI, as its equivalence classes.
Ex: if R={<1,2>,<1,1>,<2,3>,<3,2><3,4>}then
S={<1,2>,<1,1>,<2,3>,<3,2><3,4>,<2,1>,<4,3>}
3
42
1
3
42
1
Warshall’s algorithm
Let R is a relation in a set with n elements represented by matrix MR.
Calculate the matrices W0, W1, . . . , Wn where MR = W0
Wk is given by [wij(k)] where
[wij(k)] = 1, if there exists a path from vertex i to j
in the corresponding digraph, such that all the intermediate vertices of this path are in the set {1,2,…,k} 0, otherwise.
Partial order Relation
• A relation R on a set S is called a partial ordering or partial order if it is reflexive, antisymmetric, and transitive.
• A set S together with a partial ordering R is called a partially ordered set, or POSET and denoted by (S,R). A partial order R is also denoted as .
• The elements a and b of a poset (S, ) are called comparable if either a b or b a. Otherwise a and b are called incomparable.
• If (S, ) is a partial ordering set and every two elements of S are comparable, S is called a totally ordered or linearly ordered set.
• A totally ordered set is called a Chain.
Hasse Diagrams
• Given any partial order relation defined on a finite set, it is possible to draw the directed graph so that all of these properties are satisfied.
• This makes it possible to associate a somewhat simpler graph, called a Hasse diagram, with a partial order relation defined on a finite set.
• Start with a directed graph of the relation in which all arrows point upward. Then eliminate:
1. the loops at all the vertices,
2. all arrows whose existence is implied by the transitive property,
3. the direction indicators on the arrows.
• Let A = {1, 2, 3, 9, 19} and consider the “divides” relation on A:
• For all , , | for some integer .a b A a b b ka k
• For the poset ({1,2,3,4,6,8,12}, |)
S={2,3,5}, Hasse diagrams of (P(S), ) ⊆and
D30: Dn indicates the poset with set of all intergers that divide n and the relation divides.
Extremal Elements: Maximal
• An element a in a poset (S, ≤) is called maximal if no element b in S exists such that,
a ≤ b• If there is one unique maximal element a, it is
called the maximum element (or the greatest element)
Extremal Elements: Minimal
• An element a in a poset (S, ≤) is called minimal if no element b in S exists such that,
b≤ a• If there is one unique minimal element a, it is
called the minimum element (or the least element)
• Let (S, ≤) be a poset and let AS. If u is an element of S such that a ≤ u for all aA then u is an upper bound of A
• An element x that is an upper bound on a subset A and is less than all other upper bounds on A is called the least upper bound on A. We abbreviate it as lub.
• Definition: Let (S, ≤) be a poset and let AS. If l is an element of S such that l ≤ a for all aA then l is an lower bound of A
• An element x that is a lower bound on a subset A and is greater than all other lower bounds on A is called the greatest lower bound on A. We abbreviate it glb.
Give lower/upper bounds & glb/lub of the sets:
{d,e,f}, {a,c} and {b,d}
{d,e,f}
• Lower bounds: , thus no glb• Upper bounds: , thus no lub
{a,c}• Lower bounds: , thus no glb• Upper bounds: {h}, lub: h
{b,d}• Lower bounds: {b}, glb: b• Upper bounds: {d,g}, lub: d because d ≤ g
• Find all upper and lower bounds of the following subset of A: B1={a, b}; B2={c, d, e};
Find the LUB and GLB of B={6,7,10} for the following Hasse diagram.
• 1
• 2• 3 • 4
• 5 • 6 • 7 • 8
• 10• 9
• 11
Lattices
• A lattice is a partially ordered set in which every pair of elements has both – a least upper bound and– a greatest lower bound
Union, Intersection, Difference and Composition of Relations
• R: AB and S: AB
• R: AB and S: BC
}),(),(|),{( SyxRyxBAyxSR
}),(),(|),{( SyxRyxBAyxSR
}),(),(|),{( SyxRyxBAyxSR
}),(),(|),{( RyxSyxBAyxRS
}),(),(,|),{( ScbRbaBbCAcaSR
Example: Let D and S be relations on A = {1, 2, 3, 4}.D = {(a, b) | b = 5 – a}S = {(a, b) | a < b}
D = {(1, 4), (2, 3), (3, 2), (4, 1)}S = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}DS = { (2, 4), (3, 3), (3, 4), (4, 2), (4, 3), (4, 4)}
• Example: Let the relations R and S be represented by the matrices
011
111
101
SRSR MMM
001
110
101
SM
000
000
101
SRSR MMM
010
001
101
RM
• Let A = [aij] be an mk zero-one matrix and B = [bij] be a kn zero-one matrix.
• Then the Boolean product of A and B, denoted by AB, is the mn matrix with (i, j)th entry [cij], where
• cij = (ai1 b1j) (ai2 b2i) … (aik bkj).
• cij = 1 if and only if at least one of the terms(ain bnj) = 1 for some n; otherwise cij = 0.
• Let MA = [aij], MB = [bij] and MC = [cij] represent relations A, B, and C, respectively, and C = AB
• Then MC = MAMB
• MAB = MAMB
Functions
• For nonempty sets, A,B, a function, or mapping, f from A to B, denoted f:A→B, is a relation from A to B in which every element of A appears exactly once as the first component of an ordered pair in the relation.
• i.e domain(f)=A|f|=|A|Codomain=B
Properties of functions
• f: AB, is one-to-one or injective, if each element of B appears at most once as the image of an element of A.
Therefore AB.
f: AB, is one-to-one if and only if for all a1, a2A, f(a1)=f(a2) a1=a2.
• f: AB, is onto, or surjective, if range of f=Bi.e. , for all bB there is at least one aA with f(a)=B.
Therefore AB.
• f: AB, is one-to-one onto, or bijective, if f is both one-to-one and onto.
Therefore A=B.
.each for
)),((=))((
bygiven is ,:
by denoted function, composite
then the,: and : If
Aa
afgafg
CAfg
CBgBAf
( )( ) ( ( )) ( ) , ( ) , ( ) ,g f g f g a x gf x gf y 1 1 2 3 gf(4) = z
• A function f is called invertible if the converse of f is also a function. The converse is called inverse function represented by f- 1.
• The function is invertible if and only if it is one-to-one and onto, or bijective.
• Discrete numeric functions (numeric functions)
• The class of functions • whose domain is the set of natural numbers • whose range is the set of real numbers
Operations of numeric functions
Shifting
• let a be a numeric function and i a positive integer
function a is shifted i positions to the right
Find a5
Find a-7
Recurrence Relation
A recurrence relation is an infinite sequence a1, a2, a3,…, an,…
in which the formula for the nth term an depends on one or more preceding terms,
with a finite set of start-up values or initial conditions
Examples
• Fibonacci sequence
Initial conditions:
f1 = 1, f2 = 1
Recursive formula:
f n+1 = f n-1 + f n for n > 3
First few terms:
Compound interest
• Given
– P = initial amount (principal)– n = number of years– r = annual interest rate– A = amount of money at the end of n years
At the end of: 1 year: A = P + rP = P(1+r) 2 years: A = P + rP(1+r) = P(1+r)2
3 years: A = P + rP(1+r)2 = P(1+r)3
…
• Obtain the formula A = P (1 + r) n
ExamplesLinear homogeneous• an = 1.2 an-1 : degree 1
• fn = fn-1 + fn-2 : degree 2
• an = 3an-3 : degree 3
Non-linear homogeneous• an = a2
n-1 + an-2
• an = nan-1 - 2an-2
Linear non-homogeneous• an = an-1 + 2n
• hn = 2hn-1 + 1
• an = 3an-1 + n
Non-linear non-homogeneous• an = a2
n-1 + 2n
• an = n2 an-1 + n
73
The pigeonhole principle
• Suppose a flock of pigeons fly into a set of pigeonholes to roost
• If there are more pigeons than pigeonholes, then there must be at least 1 pigeonhole that has more than one pigeon in it
• If k+1 or more objects are placed into k boxes, then there is at least one box containing two or more of the objects
74
Pigeonhole principle examples
• In a group of 367 people, there must be two people with the same birthday– As there are 366 possible birthdays
• In a group of 27 English words, at least two words must start with the same letter– As there are only 26 letters
75
Generalized pigeonhole principle
• If N objects are placed into k boxes, then there is at least one box containing N/k objects
76
Generalized pigeonhole principle examples
• Among 100 people, there are at least 100/12 = 9 born on the same month
• How many students in a class must there be to ensure that 6 students get the same grade (one of A, B, C, D, or F)?
– The “boxes” are the grades. Thus, k = 5– Thus, we set N/5 = 6– Lowest possible value for N is 26
top related