I am given this algorithm (pseudo code, not in any specific language):
foo1(l,m,n){
for ( i = 1; i < l, i++){
for( j = 1; j < m ; j++){
for ( k = 1; k < n; k++){
//Constant time inner loop
}
}
}
}
I am trying to find the number of times he inner loop runs in respect to l, m, and n and come up with a function for it. I also am trying to figure out the big-O notation for the algorithm.
Looking at the algorithm, I was thinking that the inner loop would run l*m*n times. I came up with this because for example, if l,m,n were 3, 6, 9 respectively, then the inner loop would run(9*6*3) times. So the function that would return the number of times the inner loop runs would be something like:
f = l*m*n
Now the big-O is where I am struggling with (not necessarily with this problem) but I wanted to get some further insight as so how to tackle big-O problems to best determine the right big-O for an algorithm.
For this specific case, I was thinking that the big-O would be n^3 but that is just based on a guess really. How do I go about figuring out what the big-O actually is for this problem, and more generally for other algorithms I may encounter?