[algogeeks] Re: Majority Element

2011-02-14 Thread sankalp srivastava
What is a majority element ? If you are refering to your previous post , then , use hashing On Feb 13, 10:12 pm, Akshata Sharma akshatasharm...@gmail.com wrote: oops... ignore the post :-/ On Feb 13, 10:07 pm, Akshata Sharma akshatasharm...@gmail.com wrote: Given an element and an array,

[algogeeks] Re: Majority Element

2011-02-13 Thread Akshata Sharma
oops... ignore the post :-/ On Feb 13, 10:07 pm, Akshata Sharma akshatasharm...@gmail.com wrote: Given an element and an array, how will you find whether the element is the majority element of the array or not in linear time? -- You received this message because you are subscribed to the

[algogeeks] Re: majority element in array in O(n)

2010-09-10 Thread Dave
One problem in your algorithm is that the additional array has to be large enough to handle all of the values in the array, so, e.g., multiply all of your values by a million and you will see that the work goes up by a factor of a million. It can be done without the additional array, and

[algogeeks] Re: majority element in array in O(n)

2010-09-10 Thread jagadish
Hi Bittu, Your algorithm uses Linear extra space. which is proportional to the input used. There is a better algorithm which is linear in time and does alot better . int Majoritycount(int [] A) { int ctr=1; //counter is a variable to indicate the relative importance of the element. as

[algogeeks] Re: majority element

2006-11-07 Thread J.Guo
**Presume the majority exists**, the following algo use O(1) space and only scan the array one pass. It is simple idea of counting. If there exists a majority elements in the array, it must be the remaining element on the counter after we consider all elements. int getMajority(int A[], int n){

[algogeeks] Re: majority element

2006-11-03 Thread wade
ericunfuk wrote: Arunachalam wrote: Search the groups, this problem is already solved in O(n) time in the groups. regards Arunachalam. I solved it with n/2 case, I dont see how to do that with n/t, t arbitrary. I think this is equivalent to sorting. Consider the special case

[algogeeks] Re: majority element

2006-11-02 Thread Arun
hash table :)if u dont like O(n) space, a st.forward approach is sorting. this will take of any value of m, but ofcourse O(nlgn) time On 11/1/06, ericunfuk [EMAIL PROTECTED] wrote: Dear all,I have worked out the following algorithm for finding the majorityelement(the element occurs more than n/2

[algogeeks] Re: majority element

2006-11-02 Thread [EMAIL PROTECTED]
It seems that you gotta use the median algrithm. Here's some idea without implementation, I wish it will help. if the array has an odd number of lements, then the array can be devided into 3 parts: Head, Median, Tail If an element occurs more than n/m times, then at least in Head or in Tail it

[algogeeks] Re: majority element

2006-11-02 Thread Arunachalam
Search the groups, this problem is already solved in O(n) time in the groups. regards Arunachalam. On 11/2/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: It seems that you gotta use the median algrithm. Here's some ideawithout implementation, I wish it will help. if the array has an odd number of

[algogeeks] Re: majority element

2006-11-02 Thread ericunfuk
Arunachalam wrote: Search the groups, this problem is already solved in O(n) time in the groups. regards Arunachalam. I solved it with n/2 case, I dont see how to do that with n/t, t arbitrary. Thanks --~--~-~--~~~---~--~~ You received this message

[algogeeks] Re: majority element

2006-11-01 Thread shisheng li
I think the straightforward method it as followed: Suppose n = 2, m = 7 Check the 2-th ,4-th,6-th elements For general n m, there will be at most m/n such elements, by check them one by one, u just need O(m/n * m) time If n = theta(m), of course, the algorithm is O(m). Otherwise, if n m,

[algogeeks] Re: majority element

2006-11-01 Thread ericunfuk
I think there should be an algorithm that uses the theta(n) finding median subroutine. Somehow we divide and conquer, i.e. some generalization of n/2 majority element case. Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the