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 <negi.1...@gmail.com> 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 ... <shivsinha2...@gmail.com> wrote:
>
>> In constant space??? How? will you please elaborate?
>>
>>
>>
>> On Thu, Aug 5, 2010 at 9:29 PM, dinesh bansal <bansal...@gmail.com>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 algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> 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 algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to