C++, finding 3 max values in array, where difference between these values is one of the parameter -


i have find 3 max values in array of real data. problem fact these 3 values must vary particular, minimum value (which parameter). means if have array 10 elements {1,2,3,4,5,6,7,8,9,10} 3 max values in array 8,9,10 if value of parameter example "2" these 3 max values must vary @ least "2", real max values in case 10, 8, 6. believe algorithm of program this:

1) find 3 max values (loop) 2) verify if vary @ least parameter 2a) if yes return these 3 values 2b) if not, go loop, search again 3 values ignore value doesn't fulfill condition?

i can't imagine real code in c++ solution. can give piece of advice how it?

easier sorting scan array 3 times. first time, find max. next time, find largest number <= (max - p) etc.

have studied big-o notation evaluation of algorithm performance?

compare time sort & search (n * lg(2)n + n) time search 3 times (3*n) break-even performance happens @ pretty small value of n.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -