If the case values are dense (such as just the integers from 0 to 9), the compiler will turn it into a jump table.
If too sparse for jump table, then typically will be turned into a binary search tree.
233 karma · joined March 14, 2016
If the case values are dense (such as just the integers from 0 to 9), the compiler will turn it into a jump table.
If too sparse for jump table, then typically will be turned into a binary search tree.
I don't disagree, though, that online education is not as good as in-person, regardless of how it's done.
Regardless, the fact that no location is revealed will make it hard for manual resolution of false positives. On the other hand, if location was revealed, likely fewer people would opt-in, so there are both advantages and disadvantages of not using location at all.
Advantage would be that it would not require liquids of any kind and not be labor intensive.
That said, "time complexity" is a bit of a misnomer anyway. It's often implied, but underneath, there is a specific operation. For example, when we say that merge sort is O(N lg N), we mean in number of comparison operations.
In the ideal world, there would be three separate documents for the above, but PowerPoint is good enough at all of them that we tend to just create a single document that does all three.
int f1(int n) {
int sum = 0;
for (int i = 0; i < n; i++) {
int x = i + i;
sum = x - i;
}
return sum;
}
int f2(int n) {
int sum = 0;
int x;
for (int i = 0; i < n; i++) {
x = i + i;
sum = x - i;
}
return sum;
}
when compiled with 'gcc -O -S' gives: .file "loop.c"
.text
.globl f1
.type f1, @function
f1:
.LFB0:
.cfi_startproc
testl %edi, %edi
jle .L4
movl $0, %eax
.L3:
addl $1, %eax
cmpl %eax, %edi
jne .L3
subl $1, %eax
ret
.L4:
movl $0, %eax
ret
.cfi_endproc
.LFE0:
.size f1, .-f1
.globl f2
.type f2, @function
f2:
.LFB1:
.cfi_startproc
testl %edi, %edi
jle .L9
movl $0, %eax
.L8:
addl $1, %eax
cmpl %eax, %edi
jne .L8
subl $1, %eax
ret
.L9:
movl $0, %eax
ret
.cfi_endproc
.LFE1:
.size f2, .-f2
.ident "GCC: (GNU) 7.2.0"
.section .note.GNU-stack,"",@progbits
Even when compiled without optimization, the generated assembly was the same, though it was messier so I don't show it.