1
$\begingroup$

I have N apples and M oranges and few random pairs of (N+M) children.

Distribute N apple and M orange among (N+M) children in such a way that, minimum numbers of pairs of children can have different fruits in a pair.

For better understanding lets take an example:

Ex 1) 2 apples and 1 orange and children=(2+1)=3
Given pairs of children are: (1,2) (2,3)
Now if i give an apple to 1 and 3 and orange to 2, then i will have two pairs with different fruits in a pair. i.e (apple,orange) (orange,apple)

But if i give an apple to 1 and 2 and orange to 3, then i will have only one pair with different fruits in a pair. i.e (apple,apple) (apple,orange).

So answer here is 1 pair which is minimum.

Note:
Number of pairs can be anything but >0 and <= nCr(n=no. of children and r=2)

  • 0
    Don't you mean $N+M$ instead of $N+m$, in the first sentence? And another time, please use MathJax, it make reading the math much easier. :)2017-01-27
  • 0
    @Lovsovs yup it is N+M,sorry typing mistake,let me edit.2017-01-27
  • 0
    Not that it's worth much, but there is a graph-theoretical way to formulate it: Given a (possibly disconnected) graph of $N+M$ vertices, color $N$ vertices green and $M$ vertices orange so that the number of neighboring pairs of vertices with different colors is as small as possible.2017-01-27
  • 0
    @Arthur Will try it,Thanks for the hint.2017-01-27

1 Answers 1

2

Your problem is equal to the problem called graph partitioning.

Let every child be a vertex $v$ and every chosen pair be an edge $e$ in graph $G$.
To find apple and orange distribution between children is to find a partition of the graph vertex set $V(G)$ into 2 parts $V_1$ and $V_2$ such as $|V_1|=N$, $|V_2|=M$ and $V_1\cap V_2=\emptyset$,
while minimizing the number of edges between parts ( edges $(v,u)\in E : v \in V_1$ and $u \in V_2$ ).
The minimization of this edge number will minimize the number of pairs that have different fruits in it.

enter image description here

Also, the graph bisection problem which is known to be NP-hard can be reduced to your problem, so your problem is NP-hard too. (Proof: Let $N = M$)

So, if you want to find an algorithm for your problem you can use algorithms for graph partitioning. This survey can help you to find a better one for your needs.