### Thread: Need the best way/algorithm to use for following condition?

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2012
Posts
1
Rep Power
0

#### Need the best way/algorithm to use for following condition?

Hi all,
Lets take example first
I have a list of users having different values of A,B,C.
user A B C
User 1. test1 A1 B1 C3
User 2 test2 A1 B1 C1
User 3 test3 A2 B3 C3

A contains element in range of (1-400)
B contains element in range of (1-200)
C contains element in range of (1-300)

So i need to develop a algorithm that gives me the result in very quick time whenever i query for those variable A,B,C
ex. give me users whose A=A1, B=B1, C=C3 [Answer should be test1]
i can also say give me users whose A=A1[Answer should be test1,test2]

Thanks
Nikhil
2. No Profile Picture
Contributing User
Devshed Loyal (3000 - 3499 posts)

Join Date
May 2004
Posts
3,417
Rep Power
891
Build three lists of value and name-list pairs from the original data source. Then for each criteria in the query, find the union of the specified lists. So for A=2, you just look in the A list for value=2 and return the list of names (test3) and for A=1, B=1 take the union of the A=1 result and the B=1 result (test1,test2).