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

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    5

    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. #2
    coder
    Join Date
    Feb 2008
    Posts
    127
    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

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    Thanks for reply,

    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. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    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. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    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,
    Last edited by prayami; 03-17-2008 at 04:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 02:02 PM
  2. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 04:03 PM
  3. binary search in an array
    By brianptodd in forum C++ Programming
    Replies: 4
    Last Post: 11-12-2002, 02:05 PM
  4. Binary Search on an Array of Struct
    By curwa1 in forum C++ Programming
    Replies: 3
    Last Post: 10-25-2002, 02:02 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM