this finds first and last index in pair structure in logn
void repindxs(int array[],int start, int end, int k, pair<int, int> *p, int
n/*last index*/)
{
if(start>end) return ;
int m = (start+end)/2;
if( array[m] == k && (m-1<0?-1:array[m-1] <k) )
p->first = m;
else if(array[m] >k || (array[m]==k && array[m-1]==k))
repindxs(array,start,m-1,k,p,n);
if( array[m] == k && (m+1>n?-1:array[m+1] !=k) )
p->second = m;
if(array[m]<k || (array[m]==k && array[m+1]==k))
return repindxs(array,m+1,end,k,p,n);
}
surender
On Wed, Nov 9, 2011 at 1:11 AM, PIYUSH MADAN <[email protected]>wrote:
> Suppose the array is not sorted and we have to find if an element has
> occurred earlier or not; and if yes, then remove
> it.................................what is the best achievable time and how?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.