Cubic complexity

In the case of cubic complexity, the processing time of an algorithm is proportional to the cube of the input elements. The complexity of the following algorithm is 10*10*10 = 1,000. The three loops have a maximum of 10. The cubic complexity for a matrix update is O(n3).

Cubic complexity O(n3) is explained in the following example:

//main package has examples shown// in Hands-On Data Structures and algorithms with Go bookpackage main// importing fmt packageimport ( "fmt")// main methodfunc main() {var k,l,m intvar arr[10][10][10] int for k = 0; k < 10; k++ {for l=0; l < 10; l++ {for m=0; m < 10; m++ {arr[k][l][m] = 1fmt.Println("Element value ",k,l,m," is", arr[k][l][m])}}}}

Run the following commands:

go run cubic_complexity.go ...

Get Learn Data Structures and Algorithms with Golang now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.