0

I have a lot of short arrays(10-20 elements). What is best way(i mean speed) to found one element in each array? Binary search, tries, hashtable etc?

Neir0
  • 12,849
  • 28
  • 83
  • 139

1 Answers1

1

Measure at least three approaches:

  1. Linear search
  2. Binary search
  3. Hashtable

Measure them for different input sizes and choose the best method at runtime depending on the size of the array.

You could also investigate perfect hashing which trades a big upfront calculation that only needs to be done once for very fast lookup.

usr
  • 168,620
  • 35
  • 240
  • 369