Questions about Big O notation

Asked 2 years ago, Updated 2 years ago, 109 views

for (i=0; i<n/2; ++i)
    for (j=0; j<n*2; j++)
        for (k=0; k<100; k++)
            m++;

How do you represent this code in Big Five notation?

big-o

2022-09-21 11:35

1 Answers

The code of the question is not properly highlighted, so it's hard to see.

If n is an input value in the algorithm,

The last for statement (for(k=0;k<100;k++)) is not dependent on n so

Exponential is going to be 2, not 3.

Simplified

O(n/2 * 2n * 100) == O(100n2 ) == O(n2 )

22

That is, O (n2).

2


2022-09-21 11:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.