i
goes from 1
to 2n
(inclusive), so first thought is 2n
.
But we see that i
increments by two at a time instead of one, so it's half of that: n
.
number of executions in an algorithm
-
05-07-2023 - |
Vra
For this algorithm:
i = 1
while(i<=2n){
x = x + 1
i = i + 2
}
can someone tell me how to find the formula for the number of times x = x + 1 is executed?
Oplossing
Ander wenke
With n<1 number of times executed=0. With n>=1 number of times executed=n.
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow