How b is O( n/2)?


#1

Comment body goes here.


#2

lets consider you have input of size 100 then if you increment it by 2 then after 50 turns it will reach all your input size.Thats why here also the complexity is O(n/2)


#3

the update operator(i+=2) increase the value of i by 2 each time so it goes like 1,3,5,7,9,… so on so in each iteration we overlook one value so that’s why for n values we overlook n/2 values, that means we only iterate for (n-n/2)= n/2 times that’s why time complexity is 0(n/2)


#4

the time complexity of 1st for loop is o(n)
the time complexity of 2st for loop is o(n/2),equilanet to 0(n) in asympotic analysis
the time complexity of 3rd for loop is o(logn)
the time complexity of 4th for loop doesnt terminate