We should use counting sort.
There are only 256 key value, so aux array will have only 256 values, and in O(n) time and 2 passes we will be able to sort in efficient way.
We should use counting sort.
There are only 256 key value, so aux array will have only 256 values, and in O(n) time and 2 passes we will be able to sort in efficient way.
shanky - Nov 0, 2014
for(int j=arrIndex/2 ; j < arrIndex;j++)
{
if(array[j]==1)
return j;//this is our index
}
This makes the approach O(n)
Do a regular binary search after finding the cap , with range i/2 to i
Hi Shanky, you are right. That’s what I have done :)
RM - May 3, 2014
in your Pseudocode, the if condition should be if (low < high).
Thanks Rish. I have made the change a[low] > a[high] rather than low < low. :). Thanks for correcting me.