looks like the number will be median which we can find find in linear time.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to