Hi guys,
A rather different approach to the problem
The idea is that the number is appearing more than N/2 times is the majority.
1. Pair the consecutive elements like 1st an 2nd element, 3rd and 4th and so on
2. Now if both elements in the pair are the same choose both else drop both
3. Repeat steps 1 and 2 till we are left with the majority element alone
Worst case (N/2+1) is element X and (N/2-1) is element Y, this would take nlogn.
Regards
karthik
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
- [algogeeks] Re: find the most occured (more tha... Praveen
- [algogeeks] Re: find the most occured (more... Googmeister
- [algogeeks] Re: find the most occured (... Pradeep Muthukrishnan
- [algogeeks] Re: find the most occur... Vikram Venkatesan
- [algogeeks] Re: find the most ... Pradeep Muthukrishnan
- [algogeeks] Re: find the m... Vikram Venkatesan
- [algogeeks] Re: find the most occured (more tha... Praveen
- [algogeeks] Re: find the most occured (more than N/2... Amit Banwari
- [algogeeks] Re: find the most occured (more tha... Praveen
- [algogeeks] Re: find the most occured (more... Karthik Singaram L
- [algogeeks] Re: find the most occured (... Praveen
- [algogeeks] Re: find the most occur... Vinodh Kumar
- [algogeeks] Re: find the most ... Praveen
- [algogeeks] Re: find the m... Arunachalam
- [algogeeks] Re: find the m... Praveen
- [algogeeks] Re: find the m... Vinodh Kumar
- [algogeeks] Re: find the m... Dhyanesh
- [algogeeks] Re: find the m... Siva
- [algogeeks] Re: find the m... subrahmanyam kambala
- [algogeeks] Re: find the m... Googmeister
