Array $A$ of $n$ elements has min, max. Prove that exist $1\le i\le n$,$1\le j\le n$, $i\neq j$ such that $0\le A[i]-A[j]\le \frac{max-min}{n-1}$

69 Views Asked by At

Let there be a max and min value in an array $A$ of $n$ elements. Prove that exist $1\le i\le n$,$1\le j\le n$, $i\neq j$ such that $0\le A[i]-A[j]\le \frac{max-min}{n-1}$.

I'm not sure how to prove this but maybe we can sort the array $A$ first. Then we can create another array $B$ of length $n-1$ where element $B[i]=A[i+1]-A[i]$ which will be the difference of two adjacent elements in $A$ (after it's sorted).

Then $\frac{max-min}{n-1}$ is the average of $B$ so if it's the average then there must be values lesser than or equal to the average.

Am I in the right direction?

1

There are 1 best solutions below

0
On BEST ANSWER

If the array has two equal elements, then we are done.

If all the elements in the array are distinct, let $i_1, i_2, \ldots, i_n$ be a permutation of $\{1, 2, \ldots, n\}$ such that $A_{i_1} < A_{i_2} < \ldots < A_{i_n}$ is the sorted list of elements. Define the $n-1$ differences $d_k = A_{i_{k+1}} - A_{k}$ for $k = 1, \ldots, n-1$. As all elements are distinct, we have $d_k > 0$.

The sum of the differences $d_{k}$ is: $$ \sum_{1}^{n-1} d_{k} = \sum_{1}^{n-1} A_{i_{k+1}} - A_{i_{k}} = A_{i_{n}} - A_{i_{1}} = max - min $$

If $d_{k} > \frac{max - min}{n-1}$ for all $k = 1, \ldots , n-1$ then $$ \sum_{1}^{n-1} d_{k} > \sum_{1}^{n-1} \frac{max - min}{n-1} > max - min $$

Which contradicts the fact that sum should equal $max - min$. Therefore for at least one value of $k$ we have $d_{k} \le \frac{max - min}{n-1}$.