From charlesreid1

(Fix math syntax: use \cdot to separate variables in O(x·y·z) (via update-page on MediaWiki MCP Server))
 
(One intermediate revision by the same user not shown)
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(xyz)</math>
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>.




=Flags=


{{AlgorithmsFlag}}


{{AlgorithmComplexityFlag}}


{{CSFlag}}
{{AlgorithmComplexityFlag}}
[[Category:Java]]
[[Category:Java]]
[[Category:C]]
[[Category:C]]

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










See also: