I have a few questions so please bear with me. I need some help to clarify Big O and run time. As I understand it Big O is a way of presenting the run time of an algorithm correct? From reading I’ve been trying to figure out how to calculate the Big O of an algorithm. So far I’ve figured out that something like this has a Big O of O(N^2)
for(i = 0; i < N, i++)
for(j = 0; j < N; j++)
//code
But what happens if it is this:
for(i = 0; i < N, i++)
for(j = 0; j < M; j++)
//code
Where N isnt always equal to M.
Also what is the Big O if you have two of these added together?
for(i = 0; i < N, i++)
for(j = 0; j < N; j++)
//code
for(i = 0; i < N, i++)
for(j = 0; j < N; j++)
//code
Is the big O equal to N^2 + N^2 = 2N^2?
Then it is
O(NM), unlessMis dependent onNor vice versa. If they are independent, then it is also true to say that it isO(N)andO(M).O(2N^2)is equivalent toO(N^2).