1

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 ??

TN888
7,7499 gold badges53 silver badges85 bronze badges
asked Dec 26, 2012 at 12:56
4
  • Are you looping through all of the combinations? then 60 iterations is the minimum number you're going to have. Commented 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 ?? Commented Dec 26, 2012 at 13:04
  • 1
    What other approach would there be? Anyway, 240 iterations is nothing. Even 10000 iterations may be nothing. Commented 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 numbers Commented Feb 20, 2014 at 21:21

1 Answer 1

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.

answered Dec 26, 2012 at 13:09
Sign up to request clarification or add additional context in comments.

3 Comments

Mike, thanks for the response...here again i need to do validation on those 5 number and return the rank for those 5 numbers so all those 60 possible iterations will have a rank and i need to pick the best rank out of 60 iterations ??
In that case, database will suit your needs. You can make a table with fields 'combination' (which will store the numbers separated by e.g. a comma) and 'rank' and just retrieve them accordingly.
How are you calculating the rank for each 5 number combination? You might be able to achieve more optimization if there are patterns.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.