Complete a partially filled transitive relation

59 Views Asked by At

Is there any particular algorithm to complete (as much you can) a partially filled transtive relation (given in matrix form)?

You can assume that the given partially filled matrix mat[1:n][1:n] is reflexive and symmetric.

For 1<=i<=n and 1<=j<=n, mat[i][j]=1 denotes that i and j are related, mat[i][j]=0 denotes that i and j are not related and mat[i][j]=-1 denotes that the relation between i and j is not known till now.

For example:

 1  1 -1  1 -1
 1  1  1 -1 -1
-1  1  1 -1 -1
 1 -1 -1  1  1
-1 -1 -1  1  1

will be filled as

 1  1  1  1  1
 1  1  1  1  1
 1  1  1  1  1
 1  1  1  1  1
 1  1  1  1  1