Algorithm Analysis/Matrix Multiplication: Difference between revisions
From charlesreid1
No edit summary |
(Fix math syntax: use \cdot to separate variables in O(x·y·z) (via update-page on MediaWiki MCP Server)) |
||
| Line 12: | Line 12: | ||
</pre> | </pre> | ||
Each loop is proportional to O(x), O(y), and O(z), respectively, so the overall order of the computation is <math>O( | Each loop is proportional to O(x), O(y), and O(z), respectively, so the overall order of the computation is <math>O(x \cdot y \cdot z)</math> | ||
If the dimensions are all equal, this is a cubic algorithm <math>O(n^3)</math>. | If the dimensions are all equal, this is a cubic algorithm <math>O(n^3)</math>. | ||
Latest revision as of 23:23, 5 June 2026
Consider the following matrix multiplication code in C:
for(i=1; i<=x; i++) {
for(j=1; j<=y; j++) {
C[i][j] = 0;
for(k=1; k<=z; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
Each loop is proportional to O(x), O(y), and O(z), respectively, so the overall order of the computation is $ O(x \cdot y \cdot z) $
If the dimensions are all equal, this is a cubic algorithm $ O(n^3) $.
Flags
| Algorithms Part of Computer Science Notes
Series on Algorithms
Algorithms/Sort · Algorithmic Analysis of Sort Functions · Divide and Conquer · Divide and Conquer/Master Theorem Three solid O(n log n) search algorithms: Merge Sort · Heap Sort · Quick Sort Algorithm Analysis/Merge Sort · Algorithm Analysis/Randomized Quick Sort
Algorithms/Search · Binary Search · Binary Search Modifications
Algorithms/Combinatorics · Algorithms/Combinatorics and Heuristics · Algorithms/Optimization · Divide and Conquer
Algorithms/Strings · Algorithm Analysis/Substring Pattern Matching
Algorithm complexity · Theta vs Big O Amortization · Amortization/Aggregate Method · Amortization/Accounting Method Algorithm Analysis/Matrix Multiplication
Estimation Estimation · Estimation/BitsAndBytes
Algorithm Practice and Writeups Project Euler · Five Letter Words · Letter Coverage
|
| Computer Science notes on computer science topics on the wiki, for educational and learning purposes
Part of the 2017 CS Study Plan.
Python/Exceptions · Python/Assertions · Python/Decorators Python/Os (os module) · Python/Strings Python/Splat · Python/Iterators · Python/Generators Python/Comparators · Python/Lambdas
Builtin features of Java: Java/Exceptions · Java/Assertions · Java/Memory · Java/Interfaces Java/Generics · Java/Decorators · Java/Diamond Notation Java/Iterators · Java/Iterable · Iterators vs Iterable Java/Comparators · Java/Comparable · Comparators vs Comparable Java/Numeric · Java/TypeChecking · Java/Testing · Java/Timing · Java/Profiling Documentation: Javadocs · Java/Documentation Tools and functionality: Java/URLs · Java/CSV External libraries: Guava · Fastutil · Eclipse Collections OOP: OOP Checklist · Java/Abstract Class · Java/Encapsulation · Java/Generics
|
See also: