On 6/19/06, Praveen <[EMAIL PROTECTED]
> wrote:
Hi guys,
Please help in solving this problem.
u have given an array . U need to find out the element which
has
occurred more than N/2 times where N is the array length.
for ex in an array 3,4,1,3,3,3,2,6,3 ans is 3
try to do it in o(N)
I am able to do it in O(nlogn )
my solution is first sort this array
then u would be having array like this
1,2,3,3,3,3,3,4,6
after that u can use the following logic to find the element
for (int i =0;i<N/2;i++)
{
if(a[i] == a[i+N/2])
return a[i];
}
is there any better method for this.
Regards
Praveen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---
- [algogeeks] find the most occured (more than N/2 tim... Praveen
- [algogeeks] Re: find the most occured (more tha... Arun
- [algogeeks] Re: find the most occured (more... Praveen
- [algogeeks] Re: find the most occured (... Googmeister
- [algogeeks] Re: find the most occur... Pradeep Muthukrishnan
- [algogeeks] Re: find the most ... Vikram Venkatesan
- [algogeeks] Re: find the m... Pradeep Muthukrishnan
- [algogeeks] Re: find t... Vikram Venkatesan
- [algogeeks] Re: find the most occured (more... Praveen
- [algogeeks] Re: find the most occured (more tha... Amit Banwari