Search code examples
javaalgorithmclassificationranking

Algorithm to select a property out of a pool


I am writing a program to add a certain property to a column. Basically each cell in that column has a ranked set of possible properties, for example:

Cell 1 -> properties[A,G,F,T,I] Cell 2 -> properties [G,F,B,Y] . . . I want to find the most common property for all the cells so that i can apply it to the column as a whole.

Would appreciate any help. Regards


Solution

  • How about maintaining following TreeMap (it is sorted)

    TreeMap<String,Integer>
    

    for every cell you put all its properties to the map and if collision occurs, increase the reference counter for that property.

    When done, take the property(s) with the largest value of references. This would be the most common property(s). You can later retrieve the property shared by at least NUM_OF_CELLS by calling the ceilingEntry method:

    map.ceilingEntry(Integer.valueOf(NUM_OF_CELLS));