I'm looking for an algorithm that can quickly run through a short (<30 element) array and merge points that are approximately equal. It'll probably end up being some sort of segmentation algorithm.

The context is as follows: I'm looking for the tallest peaks in a dataset. I've already separated the tallest maximums from the dross using a one-dimensional implementation of J-SEG, but anywhere where the dataset is "flat," I get back a point for every element along the plateau. I need to be able to adaptively merge these points to a single point at the center of the plateau. (This also means I don't know how many clusters there will be.)

Sample dataset 1 (Sample/Artificial input) Input:

97  54686024814922.8
118 406406320535.935
148 24095826539423.7
152 1625624905272.95
160 1625625128029.81
166 1625625152145.47
176 1625625104745.48
179 1625625127365.09
183 1625625152208.44
190 1625624974205.81
194 21068100428092.9
247 54686024895222.1

Ideal Output:

97  54686024814922.8
118 406406320535.935
148 24095826539423.7
159 1625625061816.08


182 1625625089631.21



194 21068100428092.9
247 54686024895222.1

Sample dataset 2 (Real input): Input:

2   196412376940671
123 206108518197124
135 194488685387149
148 178463949513298
154 192912098976702
156 195042451997727
161 195221254214493
168 204760073508681
172 189240741651297
182 191554457423846
187 215014126955355
201 202294866774063

Ideal output:

2   196412376940671
123 206108518197124
135 194488685387149
148 178463949513298
157 194391935062974


168 204760073508681
172 189240741651297
182 191554457423846
187 215014126955355
201 202294866774063

Sample Dataset 3 (Real input) Input:

2   299777367852602
26  263467434856928
35  293412234811901
83  242768805551742
104 226333969841383
107 227548
Edit
Report