Skip to contents

Returns the adjacency matrix of the cartesian product of two graphs given the adjacency matrix of each one, \(G\) and \(H\).

Usage

cartesian(G, H = NULL)

Arguments

G

adjacency matrix of the first graph.

H

adjacency matrix of the second graph. If not provided, it takes the same value as G.

Value

Let \(A(G),\ A(H)\) be the adjacency matrices of the graphs \(G,\ H\) such that \(|V(G)| = n\) and \(|V(H)| = m\), then the adjacency matrix of the cartesian product \(G \times H\) is given by

$$A(G \times H) = A(G) \otimes I_{m\ x\ m} + I_{n\ x\ n} \otimes A(H)$$

See also

Examples

P3 <- matrix(c(0,1,0,1,0,1,0,1,0), nrow=3)
K3 <- matrix(c(0,1,1,1,0,1,1,1,0), nrow=3)

# Return the adjacency matrix of P3 X K3
cartesian(P3, K3)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#>  [1,]    0    1    1    1    0    0    0    0    0
#>  [2,]    1    0    1    0    1    0    0    0    0
#>  [3,]    1    1    0    0    0    1    0    0    0
#>  [4,]    1    0    0    0    1    1    1    0    0
#>  [5,]    0    1    0    1    0    1    0    1    0
#>  [6,]    0    0    1    1    1    0    0    0    1
#>  [7,]    0    0    0    1    0    0    0    1    1
#>  [8,]    0    0    0    0    1    0    1    0    1
#>  [9,]    0    0    0    0    0    1    1    1    0

# Return the adjacency matrix of P3 X P3
cartesian(P3)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#>  [1,]    0    1    0    1    0    0    0    0    0
#>  [2,]    1    0    1    0    1    0    0    0    0
#>  [3,]    0    1    0    0    0    1    0    0    0
#>  [4,]    1    0    0    0    1    0    1    0    0
#>  [5,]    0    1    0    1    0    1    0    1    0
#>  [6,]    0    0    1    0    1    0    0    0    1
#>  [7,]    0    0    0    1    0    0    0    1    0
#>  [8,]    0    0    0    0    1    0    1    0    1
#>  [9,]    0    0    0    0    0    1    0    1    0