Thread: Fastest way to search the table ( or array )

1. Fastest way to search the table ( or array )

Hi,

I got one, two dimensional array.
MyArray[1000][2].

Both the array i.e.
MyArray[0][0]........
MyArray[0][1].......

are filled with some values.
We will have minimum and maximun value for both the columns.
e.g.

For value_0 = 4.056 the minimum_v_0 = 4.05 and maximum_v_0 = 4.057
And
value_1 = -201.375 the minimum_v_1 = -201.380 and maximum_v_1 = -201.370

Now with each element in the array:
MyArray[0][0]......MyArray[0][1000] will be checked, whether it is falling with minimum_v_0
and maximum_v_0
AND
MyArray[1][0]......MyArray[1][1000] will be checked, whether it is falling with minimum_v_1
and maximum_v_1.

Means,
If both the column elements in a particular row will have values between corresponding
minimum and maximum value for that column then that row will be selected.

Make sure here both the column values must fall within corresponding range.

Please help me to do the fastest method for reaching to the value. We may require to arrange the
existing data in some structured form and develop the search algorithm.

Thanks,

2. We can help you of course, but we need a point to start from.
Do you have any idea of how to get the solution? Did you write some code?
The first move is up to you.

Thanks

Right now I have simple logic i.e. check all the array elements one by one.
If I have even little idea to do this another way then I would do it.

I am looking for the same thing i.e. direction or point to start with.

Thanks,

4. are you searching for a single value or a range? Are you only searching static data or do you want to efficiently support updates and inserts as well?

It sounds like you want to search for the range between a parameter max and min. In this case you'll likely want some sort of tree structure.

5. whats teh type fo th values in the array, there may be some optimizations that coudl speed things up, but wihtout knowing if they are bytes or doubles or somethign else I can't help that much. I would suggest multithreaded search and reduction, but with such small arrays the system overhead fo starting several threads would eat any gains in performance.

6. I have two dimentional array of double.
e.g.
double MyArray[1000][2];

Now,
For column MyArray[1000][0]
Conditional 1: minimum_v_0 = 4.05 and maximum_v_0 = 4.057
And
For column MyArray[1000][1]
Condition 2: minimum_v_1 = -201.380 and maximum_v_1 = -201.370

In the array MyArray[1000][], we want to find the row where the above conditions match.

e.g. If the minimum and maximum conditions give as above for both the columns. The following
row 400 should be selected.
MyArray[400][0] = 4.056
MyArray[400][1] = -201.375

Now if there are more than one rows which both the columns fall in the corresponding
range then I don't mind which row is selected. May be which ever comes first in the logic.

I hope this explains the requirements.

Thanks,