Reputation: 155
I have this loop running inside a program:
for(int I =0;I < n;I++){
for(int it = 0; it < m; it++){
Access vector.at(it+1) & add number plus vector.at(it)
}
}
Both n & m are user input and what I want to do is run the inside loop the size of the vector (m) and store information. The outside loop is saying to repeat that process n times. So would my big O notation be O(m^n) since I'm repeating m however many times n is? Thanks.
Upvotes: 0
Views: 307
Reputation: 12907
You're performing 2 operations in the inside loop, thus you are doing a total of 2 * n * m operations, which gives a O(n*m) complexity.
Upvotes: 1
Reputation: 530960
It is O(mn), assuming that the operation inside the inner loop is O(1).
Upvotes: 1