Why the run time complexity for this logic is O(N)? The number of iterations are only half here. Please explain!
for(int i = 0; i < validData.length / 2; i++)
{
int temp = validData[i];
validData[i] = validData[validData.length - i - 1];
validData[validData.length - i - 1] = temp;
}
Big O notation is about order of magnitudes and how the complexity relates to the number of elements. O(1/2 * n) == O(n)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With