public class BoyerMooreVoting<T extends java.lang.Comparable> extends java.lang.Object implements MajorityFinder<T>
Basic idea of the algorithm is if we cancel out each occurrence of an element e with all the other elements that are different from e then e will exist till end if it is a majority element.
Majority = n/2ARRAY_IS_EMPTY, DATA_TYPE_NOT_SUPPORTED_YET, DECIMAL_RADIX, DELIMITER_COMMA, ELEMENT_NOT_FOUND, LIST_IS_EMPTY, OPERATION_NOT_SUPPORTED_YET
Constructor and Description |
---|
BoyerMooreVoting() |
Modifier and Type | Method and Description |
---|---|
T |
findMajorityElement(T[] candidates) |
boolean |
isMajority(T[] candidates,
T majorityElement) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
checkArray, checkIntArray, checkList
public T findMajorityElement(T[] candidates)
findMajorityElement
in interface MajorityFinder<T extends java.lang.Comparable>
public boolean isMajority(T[] candidates, T majorityElement)
isMajority
in interface MajorityFinder<T extends java.lang.Comparable>