Warshall algorithm is used to determine all the existing paths between different vertices of a graph.
This program is mostly scientific in nature and suitable for students, and it may not be optimized enough in terms of time complexity, etc.
We have a graph with vertices A, B, C and edges AB, BC. We give the inputs to the program according to the code.
Input
Enter your set :A,B,C
Enter the size of Relation : 2
Enter Relation 1: AB
Enter Relation 2: BCOutput
w0 = {('B', 'C'), ('A', 'B')}
w0:
[0, 1, 0]
[0, 0, 1]
[0, 0, 0]
w1:
[0, 1, 0]
[0, 0, 1]
[0, 0, 0]
w1 = {('B', 'C'), ('A', 'B')}
w2:
[0, 1, 1]
[0, 0, 1]
[0, 0, 0]
w2 = {('B', 'C'), ('A', 'C'), ('A', 'B')}
w3:
[0, 1, 1]
[0, 0, 1]
[0, 0, 0]
w3 = {('B', 'C'), ('A', 'C'), ('A', 'B')}This indicates that, apart from the initial edges, there can be an edge from A to C.