in reply to Searching first array in second array.
Hi!
You write that you use nested for. That is a very inefficient way to do it. Suppose n is the size of the array, you would need O(n^2) compares. In your case it is ~7000000*7000000, which is very much.
The following algorithm would be much faster O(n) (or ~7000000*3):
Another idea could be to sort both arrays (the perl sort-function is more efficient than a "nested-for-(bubble-)sort") and then work on the sorted arrays.
HTH, Rata
PS.: please be aware that the algorithm above does not work if the first array contains some values more than once!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Searching first array in second array.
by Corion (Patriarch) on Jan 19, 2010 at 12:19 UTC |