MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / MatrixChainRec

Function MatrixChainRec

dynamic/matrixmultiplication.go:12–23  ·  view source on GitHub ↗

MatrixChainRec function

(D []int, i, j int)

Source from the content-addressed store, hash-verified

10
11// MatrixChainRec function
12func MatrixChainRec(D []int, i, j int) int {
13 // d[i-1] x d[i] : dimension of matrix i
14 if i == j {
15 return 0
16 }
17 q := 1 << 32
18 for k := i; k < j; k++ {
19 prod := MatrixChainRec(D, i, k) + MatrixChainRec(D, k+1, j) + D[i-1]*D[k]*D[j]
20 q = min.Int(prod, q)
21 }
22 return q
23}
24
25// MatrixChainDp function
26func MatrixChainDp(D []int) int {

Callers

nothing calls this directly

Calls 1

IntFunction · 0.92

Tested by

no test coverage detected