Write a program using Warshall's algorithm to generate the transitive closure of a given relation. You may assume that the set on which the relation is defined will have no more than ten elements, and that the elements are the first n positive integers.
Input should look something like:
How many elements in the set?
Output should look like:
>> 4
Using the form "a,b" for the ordered pair (a,b), enter the ordered
pairs of the relation. Type -1 to quit.
>> 1,3
>> 3,4
>> 4,2
>> -1
The original relation (in matrix form) was:
The transitive closure of this relation is:
0
0
1
0
0
0
0
0
0
0
0
1
0
1
0
0
i.e., the set of ordered pairs {(1,2),(1,3),(1,4),(3,2),(3,4),(4,2)}.
0
1
1
1
0
0
0
0
0
1
0
1
0
1
0
0
You should run your program on three different data sets: once using the relation in the example above, once using the set {(1,2),(1,3),(4,4),(4,2),(4,3)}, and once using the set {(1,2),(2,3),(3,4),(4,5),(5,1)}.