Neir0
Neir0

Reputation: 13367

Best search method for short arrays

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?

Upvotes: 0

Views: 145

Answers (1)

usr
usr

Reputation: 171206

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.

Upvotes: 1

Related Questions