Suppose I have these values with weights --$$x_1 = 2\\x_2 = 4\\x_3 = 5\\$$There is no negative or $0$ value. I need to find $2$ element subset with maximum value computed from a function $f(\cdot,\cdot)$, lets say the function values are like this --$$f(x_1,x_2) = 10\\f(x_2,x_3) = 12\\f(x_3,x_1) = 14\\$$What I am doing is running $O(n^2)$ loop (trying all combinations) and keeping the best pair, i.e. $\{x_3, x_1\}$Is there any faster way to do this ? because my dataset can get arbitrarily large (10,000) and instead of 2 elements, I may need to compute the same with k elements ($k < \text{number of data points}$)Sorting: Unfortunately, sorting is not possible, actually the weights that I am getting is from a function, the function takes $k$ data point (any combination) at a time and returns a value, i.e. $w = f(x_i, x_j, \ldots, x_k)$ so I need to pick the $k$ subset with the best (or you can say highest) $w$ value.please help.
find the optimal combination
algorithms;optimization;sets