I wanted to ask this question about Big O Notation. To my understanding n is the number of inputs.
I got in a debate with several of my colleagues about this issue.
Suppose we have an array of arrays.
Array containing all the array has the length N. and each array in that array has the length M. So we have a matrix of N x M.
Suppose the question is calculate the sum of all array. so I will write a program like this.
let sum = 0;
for (let a = 0; a < containerArray.length; a++) {
let innerArray = containerArray[a];
for (let b = 0; b < innerArray.length; b++) {
sum += innerArray[b];
}
}
The debate is, I think this program has the time complexity of O( n ) . Why ? Because our program is not executed more than the number of inputs. Even if the number of inputs is N x M program never exceeds the number of iterations that of number of inputs. While my colleagues think since you have the nested loop, time complexity is O(n^2). Please guide me.