Answer the question
In order to leave comments, you need to log in
A way to multi-thread compare the values of two arrays. Java?
There are two arrays with string data. The first array may contain few values (4-5) or quite a lot (500-1000) , the second array contains a fixed number of rows, for example (20). What algorithm is optimal for comparing each element of the first array with all elements of the second array?
The comparison should take place as quickly as possible, for example, the banal option to take and compare each element with the entire second array can be considered long.
No code needed, just an idea how to implement it.
Answer the question
In order to leave comments, you need to log in
If you have a known and small number of rows in the second array, then create a hash table from the second array of size that guarantees no collisions between the rows of the second array and immediately indicate the index of the possibly matching row in the second array in the hash table.
As a result:
- pre-costs = calculation of the hashes of the strings of the second array (filling the table),
- comparison costs = calculation of the hash of the strings of the first array + 1 fetch operation from the array + if there is a suspicion of a match - full comparison of the string.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question