Predict Complexity:
for(i=0,j=0;i<n;i++)
{
while(a[i]>a[j])
{
j++;
}
}
it is o(n)
Predict Complexity:
for(i=0,j=0;i<n;i++)
{
while(a[i]>a[j])
{
j++;
}
}
it is o(n)
hey @be10046.19 You would also need to specify whether the array is normal or an sorted array.
and keep a check for j so that it does not go out of the bounds
that is not given in the question
It would be O(n) as even in the worst case it will only be traversing the array once. Assuming the fact that j will not go out of bounds for the array.