 # How to find Number of primitive operations and Big oh of given code ?

how can I calculate primitive operations and big oh for the given for loops individually.

``````for( int i=0; (i<=n) && (j<=m); ++i,++j)
{
sum += i;
}

for( int i=0; (i<=n) || (j<=m); ++i,++j)
{
sum += i;
}
``````

and thanks for help

Do you mean, time complexity??

The first one is O(min(n,m)) while second one is O(max(n,m))

Number of operations are 5*Time Complexity

how did you do that ? i want to know proper calculation ? and number of primitive operations like Random Access Machine model where assignment operation cost 1,any arithmetic operation cost 1, condition check cost 1 like that.

If you are clear with how i derived time complexity, then no. of operations is an easy task. We know how many times it will iterate, so sum all repeated operations * Number of times loop repeates.

Eg- 2 conditions+1 increment+2 loop var. updation = 5 operation per loop. Multiplying with number of iteration should give the answer.

Thats how i approached it. PS: I assumed cost of every operation as 1.