0

I'm terribly sorry if this has been asked before, I searched about 30 minutes before deciding to post this and didn't find anything.

I have an array of ascending numbers with no precise stepping:

12.34, 103.223, 105.3, 110, 234.45, 329.11 ...

I get a numeric input say, for example 106.45 and I need to rapidly find the closest match in my list. In this case 105.3.

I'm looking for an appropriate data-structure to accomplish this, if you could recommend one.

Insertion and deletion are not performance-critical, but finding the closest match is. The structure can be immutable, the data set doesn't change often.

thwd
  • 23,956
  • 8
  • 74
  • 108

1 Answers1

1

I'd simply prefer binary search.

Akashdeep Saluja
  • 2,959
  • 8
  • 30
  • 60