I have these two questions that I think I understand how to answer (answers after the questions). I just wanted to see if I am understanding time complexity calculations and how to find the BigO.
Generic form is just the product of each value on the right side of the expression.
The BigO is the largest power in an polynomial. Is this way of thinking correct?
int sum = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n * n; j++)
for (int k = 0; k < 10; k++)
sum += i;
How many generic time units does this code take? n(n^2)*10
What is the big-oh run time of this code? O(n^3)
Yes. Basically the definition of big O states that you the time units (as you call them) are bounded from above by a constant time you expression starting from some (arbitrarily high) natural number to infinity. In a more mathematical notation this is:
A function f(n) is O(g(n)) if there exist a constant C and a number N such that f(n) < C*g(n) for all n > N.
In your context f(n) = n(n^2)*10 and g(n) = n^3.
You could, by the way, also say that the function is O(n^4). You can use the big theta notation to indicate that this is also the lower bound: f(n) is $\theta(n^3).
See more on this here: https://en.wikipedia.org/wiki/Big_O_notation