previous up next
Go backward to Composition of Relations
Go up to Top
Go forward to
RISC-Linz logo

Composition of Relations

Written as a Java method, the composition of two adjacency matrices A and B giving a result matrix C resembles matrix multiplication:

void compose(int n, boolean[][] A, boolean[][] B, boolean[][] C)
  for (int i=0; i<n; i++)
    for (int j=0; j<n; j++)
      C[i][j] = false;
      for (int k=0; k<n; k++)
        C[i][j] = C[i][j] || (A[i][k] && B[k][j]);

Author: Wolfgang Schreiner
Last Modification: January 26, 2000

previous up next