Quickest way to compare a bunch of array or list of values.

Posted by zapping on Stack Overflow See other posts from Stack Overflow or by zapping
Published on 2010-05-13T12:54:45Z Indexed on 2010/05/13 13:14 UTC
Read the original article Hit count: 215

Filed under:
|
|
|

Can you please let me know on the quickest and efficient way to compare a large set of values. Its like there are a list of parent codes(string) and each code has a series of child values(string). The child lists have to be compared with each other and find out duplicates and count how many times they repeat.

code1(code1_value1, code1_value2, code3_value3, ..., code1_valueN);
code2(code2_value1, code1_value2, code2_value3, ..., code2_valueN);
code3(code2_value1, code3_value2, code3_value3, ..., code3_valueN);
    .
    .
    .
codeN(codeN_value1, codeN_value2, codeN_value3, ..., codeN_valueN);

The lists are huge say like there are 100 parent codes and each has about 250 values in them. There will not be duplicates within a code list. Doing it in java and the solution i could figure out is.

  • Store the values of first set of code in as codeMap.put(codeValue, duplicateCount). The count initialized to 0.
  • Then compare the rest of the values with this. If its in the map then increment the count otherwise append it to the map.

The downfall of this is to get the duplicates. Another iteration needs to be performed on a very large list.

An alternative is to maintain another hashmap for duplicates like duplicateCodeMap.put(codeValue, duplicateCount) and change the initial hashmap to codeMap.put(codeValue, codeValue).

Speed is what is requirement. Hope one of you can help me with it.

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays