R
R
Rockstar182014-01-28 21:59:54
Java
Rockstar18, 2014-01-28 21:59:54

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

2 answer(s)
A
Andrew, 2014-01-28
@OLS

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.

P
ponkin, 2014-02-10
@ponkin

Try first to calculate the "hash" for each keyword and then sequentially count the "hashes" for the text and compare with the keywords.
Actually, the moped is not mine. The approach is implemented in the well-known Rabin-Karp algorithm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question