Given an array of elements, Ive got two arrays that contains data identifying each element. For example, element number k is identified by the value contained in position k of both of the arrays. These arrays contain int type values and they can represent the weight and value of each element or whatever.
Im programming a greedy algotithm that picks first the elements with better relation (a/b) in their values. This can be archieved by checking first the elements with the better relation between its respective values in the arrays and to archive that Ive thought that storing the elements in one array and sorting them by the relation might be the way to go because only thing I would need in my greedy algorithm is taking the first, then the second and so on untill there isnt any more left to pick or the limit is exceeded.
My question is if there is an easy way of doing this.
Ive got a first implementation that checks both arrays in every iteration of the algorithm and picks up the element with the best relation from the remaining ones but implementing the upgrade explained above would improve the time complexity of the algorithm because selection would be O(1) instead if O(n) and thats a key thing in this problem.