day5
day5
1. Implement Matrix Chain Multiplication problem: Find the minimum number of scalar
multiplications needed for chain of matrix.
#include <stdio.h>
#include <limits.h>
int main() {
int n;
printf("Enter the number of matrices: ");
scanf("%d", &n);
int p[n];
printf("Enter the dimensions of matrices (as an array of size %d):\n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
int result = matrixChainOrder(p, n);
printf("Minimum number of scalar multiplications: %d\n", result);
return 0;
}
output:
2}1. Implement all pair shortest path problem using Floyd Warshall’s algorithm.
#include <stdio.h>
#define INF 99999
#define MAX_VERTICES 10
int main() {
int graph[MAX_VERTICES][MAX_VERTICES], V, E, i, u, v, weight;
printf("Enter the number of vertices: ");
scanf("%d", &V);
floydWarshall(graph, V);
return 0;
}
output: