Java – find the number of required items in the list?
Design an algorithm, given the list of n elements in the array, find all the elements that appear more than N / 3 times in the list The algorithm should run in linear time (n > = 0)
You should use comparison and implement linear time No hashing / too much space / and no standard linear time deterministic selection algorithm? I think the problem is self blockade?
Solution
Tip: check out Boyer and Moore's linear time volt algorithm
pace:
>Use the median algorithm to find the median of the array in 0 (n) time > partition using the median as the pivot element > use the Moore voting algorithm between each part a) median and the first element and b) median and the last element > check whether the median is a required element
For more detailed algorithms to solve this problem, please refer to this document Really, it would be very helpful
For more answers, see this similar post