algorithmexpense-splitting

Algorithm to share/settle expenses among a group


I am looking forward for an algorithm for the below problem.

Problem: There will be a set of people who owe each other some money or none. Now, I need an algorithm (the best and neat) to settle expense among this group.

Person AmtSpent
------ ---------
A       400  
B      1000  
C       100  
Total  1500

Now, expense per person is 1500/3 = 500. Meaning B to give A 100. B to give C 400. I know, I can start with the least spent amount and work forward.

Can some one point me the best one if you have.

To sum up,

  1. Find the total expense, and expense per head.
  2. Find the amount each owe or outstanding (-ve denote outstanding).
  3. Start with the least +ve amount. Allocate it to the -ve amount.
  4. Keep repeating step 3, until you run out of -ve amount.
    s. Move to next bigger +ve number. Keep repeating 3 & 4 until there are +ve numbers.

Or is there any better way to do?


Solution

  • You have described it already. Sum all the expenses (1500 in your case), divide by number of people sharing the expense (500). For each individual, deduct the contributions that person made from the individual share (for person A, deduct 400 from 500). The result is the net that person "owes" to the central pool. If the number is negative for any person, the central pool "owes" the person.

    Because you have already described the solution, I don't know what you are asking. Maybe you are trying to resolve the problem without the central pool, the "bank"?

    I also don't know what you mean by "start with the least spent amount and work forward."