what is the difference between sum of first n primes and prime(prime(n?

Why is the sum of differences of two sorted sets the same when summed in different (but specific) ways?

  • Please -- if you can think of a way to reword this please do. I am wondering also if there is a simple name for this phenomenon, or if there are cases where it's not true. Example: Given an array of random numbers with an even number of elements, sorted from smallest to largest, the sum of the absolute differences between pairs of elements is the same under two conditions: If you partition the array in half at the middle, then sum the absolute differences of the ith elements of each partition. (Call this method 1) You get the same sum of differences if you also sum the absolute difference of the first element of the first partition with the last element of the second partition, then iterate forwards on the first partition and backwards on the second. (method 2) For example: 1 2 3 4 5 6 split into 1 2 3, 4 5 6 sum absolute differences (method 1): (4-1) + (5-2) + (6-3) = 9 method 2: (6-1) + (5-2) + (4-3) = 9 I've checked this out for lots of random numbers and I think there should be a simple explanation for why this works. The numbers don't need to be unique, or positive for this to hold. This seems to work with any summed differences when permuting either partition, so the method 1 and method 2 are just 2 cases of that permutation, I think. (5-1) + (6-2) + (4-3) = 9

  • Answer:

    Because these are the same as long as you sort the array first. All the differences are guaranteed to be positive since all elements of the second array are greater than all elements of the first array. So the difference will always be the difference of the sum of elements of the second array from the sum of elements of the first. In your example, the difference can be written as (4+5+6)-(1+2+3) regardless of any permutation of individual partitions.

Shrey Banga at Quora Visit the source

Was this solution helpful to you?

Other answers

In either of the two methods, you're attaching a positive sign to every element in the right partition and a negative sign to every element in the left partition and calculating the sum. Because addition is commutative, this works out the same

Anonymous

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.