# 8.3 representing relations directed graphs –vertex –arc (directed edge) –initial vertex...

Post on 04-Jan-2016

217 views

Embed Size (px)

TRANSCRIPT

Slide 1

8.3 Representing RelationsDirected GraphsVertexArc (directed edge)Initial vertexTerminal vertexExampleDraw the divides relation on the set {2,3,4,5,6,7,8,9} as a directed graphThe zero-one Matrix Representation MRMR is just a zero-one version of the chart representation of R.23456789210101010301001001400100010500010000600001000700000100800000010900000001ReflexivityDirected graph pictureZero-one matrix pictureSymmetryDirected graph pictureZero-one matrix pictureAntisymmetryDirected graph pictureZero-one matrix pictureTransitivityDirected graph pictureZero-one matrix pictureTheorem

For relations R1 and R2 on set A,Corollary

For a relation R on set A,for any positive integer n.8.4 Closures of RelationsReflexive closure

Symmetric closurePaths in Directed GraphsA path in a directed graph is a sequence of vertices for which any two consecutive vertices ai and ai+1 in the sequence are joined by an arc from ai to ai+1.Theorem: Let R be a relation on set A, and n a positive integer. Then there is a path of length n from a to b in R if and only if (a,b) is in Rn.Example: The Connectivity Relation R*Let R be a relation on set A. We define

The Transitive ClosureFor a relation R on a set A, we define the transitive closure of R to be the smallest transitive relation containing R.Theorem:Finding transitive closure the hard way:Computing R*If A is a set with n elements, and R is a relation on A, then any time there is a path of length one or more from a to b in R then there is a path of length n or less.So actually

and

Interestingly, this is not the best way of computing R*

Computing transitive closure the better way: Warshalls Algorithmprocedure Warshall(MR: n by n zero-one matrix) W := MR for k:=1 to n for i:=1 to n for j:=1 to n wij := wij (wik wkj) { W now contains MR* }Illustration of Warshalls Algorithm8.5 Equivalence RelationsDefinition: A relation R on set A is an equivalence relation if ExamplesaRb if and only if a and b have the same first name (on the set of students in this class)

aRb if and only if a b (mod 5) (on the set of integers)Equivalence ClassesIf R is a relation on set A, and a is an element of A, thenExamples (continued)[Michael]

[4]5TheoremFor an equivalence relation R on set A and elements a and b of A, the following are all logically equivalent:a R b[a]R = [b]R[a]R [b]R

PartitionsFor a set S, a partition of S is a collection = {A1, A2, , Am} of nonempty subsets of S which satisfies the following properties:Every element of A is in one of the sets Ai.For all i, j {1, 2, , m}, if i j then Ai Aj = Terminology: We say that the collection partitions S.TheoremLet R be an equivalence relation on set S. Then the equivalence classes of R partition S. Conversely, for any partition of S there is an equivalence relation R whose equivalence classes are the sets in . , , ,-8, , ,-5, , ,-2, , ,1, , ,4, , ,7, , ,10, , ,-9, , ,-6, , ,-3, , ,0, , ,3, , ,6, , ,9, , ,-10, , ,-7, , ,-4, , ,-1, , ,2, , ,5, , ,8, , , ,-10, , ,-7, , ,-4, , ,-1, , ,2, , ,5, , ,8, , , , ,-9, , ,-6, , ,-3, , ,0, , ,3, , ,6, , ,9, , , , ,-8, , ,-5, , ,-2, , ,1, , ,4, , ,7, , ,10, Visual[2]={ ,-10, -7, -4, -1, 2, 5, 8, }[0]={ ,-9, -6, -3, 0, 3, 6, 9, }[1]={ ,-8, -5, -2, 1, 4, 7, 10, }, , ,-8, , ,-5, , ,-2, , ,1, , ,4, , ,7, , ,10, , ,-9, , ,-6, , ,-3, , ,0, , ,3, , ,6, , ,9, , Visual,-10, , ,-7, , ,-4, , ,-1, , ,2, , ,5, , ,8, , , [2]={ ,-10, -7, -4, -1, 2, 5, 8, }[0]={ ,-9, -6, -3, 0, 3, 6, 9, }[1]={ ,-8, -5, -2, 1, 4, 7, 10, }Example: Turning a partition into an equivalence relationZero-One Matrix Representation of an Equivalence Relation ExamplesDigraph Representation of an Equivalence Relation ExamplesEquivalence as samenessAlmost every equivalence relation definition comes down to identifying some notion of samenessSame remainder when divided by nSame nameSame set of a partitionNumber of Partitions of a Set with n Elementsn = 1

n = 2

n = 3

n = 4

Recurrence Relation for the Number of Partitions of a Set with n Elements8.6 Partial OrderingsLet A be a set, and R a relation on A. We say that R is a partial ordering if and only ifIn this case we say that the pair (A, R) is a partially ordered set (poset).Examples:The real numbers R under the relationThe real numbers R under the relationThe positive integers under the divides relationAny set of sets under the (subset) relationThe cartesian product ZZ under the (,) relation R. (i.e. (x,y) R (z,w) if and only if x z and y w.)

ConventionComparable and Incomparable ElementsExamples: Total OrderingsWell-Ordered SetsHasse DiagramsBegin with the digraph representation of the partial orderingOmit the reflexive loopsOmit all edges which would be implied by transitivityOrient all vertices and arcs so that the direction of each arc is up.Remove the direction arrow from each arcHasse Diagram Example IPairs in {1,2,3}{1,2,3} under lexicographic orderHasse Diagram Example IPairs in {1,2,3}{1,2,3} under lexicographic orderHasse Diagram Example IPairs in {1,2,3}{1,2,3} under lexicographic orderPairs in {1,2,3}{1,2,3} under lexicographic orderHasse Diagram Example IPairs in {1,2,3}{1,2,3} under lexicographic orderHasse Diagram Example IHasse Diagram Example IIIntegers 1-12 under dividesHasse Diagram Example IIIIntegers 1-12 under dividesMaximal and Minimal ElementsTheoremsEvery finite poset has a minimal element

Every finite poset has a maximal element

Example:Maximal Elements?

Minimal Elements?

Greatest Element?

Least Element?

Upper Bounds and Lower Bounds

Example:Find the upper and lower bounds of the subsets {c,f}, {h,i}, {c,d,e}.

Find the greatest lower bound and the least upper bound of {b,d} and {a,b,g}.Topological SortsTopological Sort AlgorithmProcedure TopologicalSort(S: finite poset)Let q be a queue of elements of S, initially emptyWhile S is not empty, do beginChoose and enqueue a minimal element s of S onto the queue q.Remove s from SEnd{ The queue q now contains all the elements of S, arranged in a compatible total ordering of S. }Topological Sort Trace

Recommended