Assignment 5
Assignment 5
int main() {
int p[] = {4, 10, 3, 12, 20, 7};
int n = sizeof(p)/sizeof(p[0]);
matrixChainOrder(p, n);
return 0;
}
Input/output:
Analysis:
1. Time Complexity Analysis:
• You are checking every way to multiply matrices from i to j.
• For each pair (i, j), you try every split point k.
• There are:
o O(n²) such pairs (all i and j)
o Up to O(n) split points (k) for each pair
• Total work = O(n²) × O(n) = O(n³)
• Time Complexity = O(n³)