I am not sure what I should be focused on when determining Big-O of functions. Sometimes it seems that the incrementing variable 'i' is what determines asymptotic complexity other times it seems like it is user defined 'n' that determines asymptotic complexity.
In example1 it seems that since there is 3 n's being multiplied that will produce a O(n^3) effect. is that right? what effect might the i = i + 1 have on the overall function? And thinking that the print statement will just produce a O(n) effect since it's nested in the loop, and all thing nested get O(n) at the very least. So overall I would guess this is O(n^3) but not entirely sure. Mainly because it's divided by 4. Not sure what effect that might have n^3/4 is that still n^3?
example1:
for (i = 1; i < (n * n * 3 * n + 17) / 4; i = i +1) {
System.out.println("Hello World);
}
For the second example, the first loop is normal, I think it's effect is n + 1 but I don't know why it's n + 1, why the + 1? why not just 'n'? All in all this (I think) will produce a O(n) in the first line. Second line is a boolean, and I am not sure how that is treated or what effect that has on the Big-O. Since it's nested in the loop it is by default O(n). In the worst case if 'i' is even the second loop will run, and now this is a nested for loop therefore it will produce a O(n^2) effect. The print statement by default will be O(n^2) too. In the else case we have another for, also being nested which mutates the 'n' by multiplying it, not sure here but if those n's weren't being multiplied the nested loop would just be O(n^2) but here we have n^2 already plus the n^2 from it being nested, so this might be O(n^4)? So maybe in the worst case it will be O(n^4)? Not sure.
example2:
for (i = 0; i < n; i++) {
if (i % 2 == 0) {
for (j = 0; j < n; j++) {
System.out.println("Hey");
} else {
for (j = 0; j < n * n; j++) {
System.out.prtinln("Now");
}
For the last example here there is n being multipled by 10000, so we immediately have an O(n) effect here. Also not sure why this is but I read that i will also effect the loop, and since "i" is i = i * 2 that will make it log_2(n) I have no idea why this is the case though. How could i = i * 2 produce log_2(n). If this is true I am thinking that the loop will maybe be nlog_2(n) because the n is being multipled by 10000, hence O(n) and then i = i * 2 produces log_2(n) so multiplied together they are nlog(n). The x = x + i; I think this is just O(n) but overall won't make much difference.
example3:
for (i = 1; i <= 10000 * n; i = i *2) {
x = x + i;
}
Please help I am very lost on all this.
Thank you