Assume I have a set of items $A$ and each item $a \in A$ has a score $s(a)$. Also, each two items $a_1,a_2 \in A$ have variety score $var(a_1,a_2)$ which tells how different they are.
I want to optimize over these two values (say with equal weights) to find $k$ items that have both high scores and large variety (to avoid almost-repetitive items). That is, to solve the following optimization problem:
$$\arg\max_{a_1,...,a_k\in A}{(\sum_{i=1}^{k} s(a_i) + \sum_{1 \le i<j\le k} var(a_i, a_j)})$$
- Is this problem NP-hard?
- If not, can you provide a polynomial time algorithm that solves it?
- If yes, can you provide a polynomial time approximation algorithm that approximately solves it?
randomized-select
store $var(a_i, a_{median})$ in a copy of an array, then partition the obtained array usingrandomized-partition
around $(len[A] - k)^{th}$ order statistic. Then take all values greater than $k$ (the ones on the right). Provided I understood the requirement properly, this is $O(n)$ time algorithm, so definitely in $NP$. $\endgroup$