I have searched a bit on StackOverflow and have understood the complexity up to the point of the j-loop, which is O(n2)
. However with the nested addi
This is quite tricky to explain without diagrams, but each nested loop will iterate "n" number of times before returning the iteration to the parent.
So as jambono points out, each nested loop requires comparison/evaluation for each iteration of "n". So "n" is compared to the local variables in each loop (n*n*n) making O(n^3).
Step the code in a debugger for a visual indication of how this complexity is processed by the machine.