How do I approximate the value of sum after the following code fragment, in terms of variable n in Big-Oh notation?

170 views Asked by At

This is the code that was provided, I don't understand what to do at all or how to get to the answer.

int sum = 0;
for (int i = 1; i <= n - 3; i++) {
    for (int j = 1; j <= n + 4; j += 5) {
        for (int k = 1; k <= n + 4; k += 5) {
                sum += 2;
        }
    }

    sum++;
}

for (int i = 1; i <= 100; i++) {
    sum++;
}

This is also another code that was provided with the same question. If someone could explain how I am suppose the figure out the answer that would be really helpful.

int sum = 0;
for (int i = 1; i <= n; i++) {
    sum++;
}

for (int j = 1; j <= n / 2; j++) {
    for (int k = 1; k <= n / 2; k++) {
        sum++;
    }
}`
1

There are 1 answers

0
Soudabeh Parsa On BEST ANSWER

this is the formula which your code is implementing:

100 + (n-3)(((((n=4)/5)+1)^2)+1) so it is N^3 order