Can someone tell me about this performance issue
I've got 2 arrays, I need to pick 5 numbers from these 2 arrays and work on the logic
the first array has got 5 number, out of which I need to pick 3 numbers and the second array has got 4 numbers, out of which I need to pick 2 number
so taking this into consideration 5c3 - 10 and 4c2 - 6 which means 60 iterations for a single case
Is the method I'm approaching the right way?? is there any performance issue on this type of iterations ??
-
Are you looping through all of the combinations? then 60 iterations is the minimum number you're going to have.irrelephant– irrelephant2012年12月26日 12:58:02 +00:00Commented Dec 26, 2012 at 12:58
-
yes, i know there are 60 iterations which i need to for a single user, what if there are 4 users, which means 4*60 = 240...omg I just want to confirm, is this the right approach ??Satish Ravipati– Satish Ravipati2012年12月26日 13:04:46 +00:00Commented Dec 26, 2012 at 13:04
-
1What other approach would there be? Anyway, 240 iterations is nothing. Even 10000 iterations may be nothing.irrelephant– irrelephant2012年12月26日 13:06:03 +00:00Commented Dec 26, 2012 at 13:06
-
u said u need 3 numbers from array one and 2 numbers from array 2. So can It be any random number? or do u have to generate all possible combinations. If its just random numbers, why dont u generate a random index for array 1 and another 1 for array 2 to get random numbersKrimson– Krimson2014年02月20日 21:21:15 +00:00Commented Feb 20, 2014 at 21:21
1 Answer 1
If you have to go through the whole array and pick numbers, then there is no optimization for that. The execution time depends on the size of arrays, meaning the bigger the size - higher execution time.
Although, if you know that it will always be exactly 5 numbers from two rows whose elements will not change, than I think you could generate all the possible valid combinations, store them in a database or file, and return a random one (if random choice is what you are looking for). In this case, you will achieve some optimization.