I have an array of items and I need to find the matching ones(duplicates). I have the simplest O(n^2) algorithm running for now. Item type doesn’t really matter, but if you want to know it’s image.
myarray;
for(i = 0; i < myarray.length - 1; i++)
for(int j = i+1; j < myarray.length; j++)
if(myarray[i] = myarray[j])
output(names of items);
I tried Wikipedia and Google, but couldn’t come out with an answer. Any links or algorithms or code in any language would be great.
Rather than sort and then compare adjacent items, why not add each item to a self balancing binary tree, thus you get the ‘already present’ check for free (sort of).