How to prove if dividing a set of natural numbers into two groups with the same average, their average will be equal to the average of original set?

58 Views Asked by At

I am doing a leetcode problem:

https://leetcode.com/problems/split-array-with-same-average/description/

The solutions are all assuming "the average of each partition is the average of the entire array when they are equal", but I cannot figure out why? Does anyone know why the assumption is true?

The solutions is here:

  1. https://leetcode.com/problems/split-array-with-same-average/discuss/120678/5ms-Short-C++-dfs-solution-with-pruning
  2. https://www.youtube.com/channel/UC1kBxkk2bcG78YBX7LMl9pQ
3

There are 3 best solutions below

0
On BEST ANSWER

Let's say that original values are $$ x_1, \ldots, x_n, y_1, \ldots, y_k. $$ Then the average of these is $$ A = \frac{1}{n+k}(x_1 + \ldots + x_n + y_1 + \ldots y_k) $$ while the averages of the individual parts are $$ B = \frac{1}{n}(x_1 + \ldots + x_n) C = \frac{1}{k}(y_1 + \ldots + y_k) $$ Now suppose that $B$ and $C$ are equal -- just use the letter $B$ -- then we get that $$ nB = (x_1 + \ldots + x_n), kB= (y_1 + \ldots + y_k) $$ Summing, we get $$ (x_1 + \ldots + x_n) + (y_1 + \ldots + y_k) = nB + kB = (n+k)B $$ so that $$ \frac{1}{n+k}\left[(x_1 + \ldots + x_n) + (y_1 + \ldots + y_k)\right] = B $$ But the left hand side is exactly the overall average $A$. So $A = B$ as required.

0
On

The sum of values of a group with $N$ members and group average $\overline x$ is simply $S = N\overline x$. This follows immediately from the definition of the average, $\overline x = \frac SN$.

Let's say a group of size $N$ is split into two sub-groups with sizes $N_1$ and $N_2$ and a common average $\overline x$.

The total sum $S$ of the original group will be the summed totals of both sub-groups, so:

$S = N_1\overline x + N_2\overline x = (N_1 + N_2)\overline x = N\overline x$.

So the original group average will also be $\overline x$, as required.

0
On

Let $A$ but one group with $a$ elements and $B$ be the other group with be elements and let $K_A = \sum_{a\in A} a$ and $K_B = \sum_b{\in B} b$.

And we are told $\frac {K_A}a = \frac {K_B}{b}$. We need to prove $\frac {K_A + K_B}{a+b} = \frac {K_A}a = \frac {K_B}{b}$.

$\frac {K_A}a = \frac {K_B}{b}\implies \frac {K_A b}a = K_B $

So $\frac {K_A}a= \frac {K_A*\frac {a+b}{a}}{a\frac {a+b}a}=\frac{\frac {K_Aa + K_Ab}a}{a+b}=\frac {K_A + \frac {K_A*b}a}{a+b}=\frac {K_A + K_b}{a+b}$