Nice solution. Reduces number of comparisons to half of Ashish's algo. The
complexity remains O[n] though. Can it be made more efficient, like O[log n]

On Thu, Aug 5, 2010 at 10:59 PM, Pramod Negi <[email protected]> wrote:

> compare pair wise i.e a[0] and a[1]....a[2] and a[3]..
>
> leave out last 4 elements...
>
> repeated element can be found in 3 comparison for these 3 elements...
>
>
> total no of comparison in worst case
> (n/2+1)
>
> Negi
>
>
> On Thu, Aug 5, 2010 at 10:55 PM, Shiv ... <[email protected]> wrote:
>
>> In constant space??? How? will you please elaborate?
>>
>>
>>
>> On Thu, Aug 5, 2010 at 9:29 PM, dinesh bansal <[email protected]>wrote:
>>
>>> If I understand the question correctly... there is an array of size n
>>> which has n/2 distinct elements and one element is repeated n/2 times.
>>>
>>> For e.g.:
>>>    n = 4:   1 2 3 3
>>>    n = 6    1 2 3 4 4 4
>>>    n = 8    1 2 3 4 5 5 5 5
>>>
>>> So now this problem can be reduced to finding the first duplicate element
>>> in the array because remaining other elements will be unique. I think this
>>> can be done in linear time.
>>>
>>>
>>>  --
>> 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]<algogeeks%[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]<algogeeks%[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.

Reply via email to