2 5 Transitive Closure 1 Transitive Closure Let

  • Slides: 12
Download presentation
2. 5 Transitive Closure 1

2. 5 Transitive Closure 1

Transitive Closure Let R be a relation on a set A. Let of R.

Transitive Closure Let R be a relation on a set A. Let of R. Three methods for finding a) Digraph Approach b) Adjacency Matrix method c) Warshall’s Algorithm be the transitive closure : 2

Example 1 Let A = {1, 2, 3, 4}, and let R = {(1,

Example 1 Let A = {1, 2, 3, 4}, and let R = {(1, 2), (2, 3), (3, 4), (2, 1)}. Find the transitive closure of R. 3

Solution Method 1: Digraph: Listing all paths Vertex 1: has paths to vertices 2,

Solution Method 1: Digraph: Listing all paths Vertex 1: has paths to vertices 2, 3, 4 and 1 (1, 2), (1, 3), (1, 4) and (1, 1) Vertex 2: has paths to vertices 1, 3, 4 and 2 (2, 1), (2, 3), (2, 4) and (2, 2) 1 Vertex 3: has path to vertex 4 (3, 4) Vertex 4: has no path to any of the vertices, including 4 4 2 3 ={(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 4)} 4

Solution Method 2: Matrix Using formula: convert R to MR R = {(1, 2),

Solution Method 2: Matrix Using formula: convert R to MR R = {(1, 2), (2, 3), (3, 4), (2, 1)} Find and 5

Solution 6

Solution 6

Solution 7

Solution 7

Solution Method 3: Warshall’s Algorithm convert R to MR R = {(1, 2), (2,

Solution Method 3: Warshall’s Algorithm convert R to MR R = {(1, 2), (2, 3), (3, 4), (2, 1)} 8

Solution Step 1: Observe value 1’s in column 1 : Observe value 1’s in

Solution Step 1: Observe value 1’s in column 1 : Observe value 1’s in row 1 : 2 2 So we have new 1 in position (2, 2). 9

Solution Step 2: Observe value 1’s in column 2 : 1, 2 Observe value

Solution Step 2: Observe value 1’s in column 2 : 1, 2 Observe value 1’s in row 2 : 1, 2, 3 So we have new 1 in position: (1, 1), (1, 2), (1, 3)(2, 1), (2, 2), (2, 3) (if 1’s are not already there) 10

Solution Step 3: Observe value 1’s in column 3 : 1, 2 Observe value

Solution Step 3: Observe value 1’s in column 3 : 1, 2 Observe value 1’s in row 3 : 4 So we have new 1 in position: (1, 4), (2, 4) (if 1’s are not already there) 11

Solution Step 4: Observe value 1’s in column 4 : 1, 2, 3 Observe

Solution Step 4: Observe value 1’s in column 4 : 1, 2, 3 Observe value 1’s in row 4 : N/A So no new 1 to add. 12