I need to find the exact operation count and i got confused over the below 2
Is a=b+c+d considered as one instruction or 2 instructions?
Similarly is a+=b one instruction or 2?
I need to find the exact operation count and i got confused over the below 2
Is a=b+c+d considered as one instruction or 2 instructions?
Similarly is a+=b one instruction or 2?
Is a=b+c+d considered as one instruction or 2 instructions?
Neither. Barring compiler optimizations, there are three operations going: two additions and an assignment. As far as instructions go, a naive interpretation would be:
mov r1, b
mov r2, c
add
mov r2, d ; Assuming add puts the result in r1
add
mov a, r1
Similarly is a+=b one instruction or 2?
It depends on how the compiler generates machine code for that kind of compound operator. But when working out time complexity, you should be looking at operations in the source language, not the resulting instructions after the source language is compiled. In that case your two example statements are 3 operations and 1 operation, respectively.
If you are looking for simple Big-O complexity, it's O(1)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.