How the Minimum-Settlement Algorithm Works (With a Real Example)
If you've ever settled up in a group by having each person pay back each person they owe, you've experienced the problem: the more people involved, the more individual transfers pile up. Four people can generate up to twelve separate transactions. The minimum-settlement algorithm is the mathematical solution to this, and it's what WariSaku uses under the hood. This article explains how it works with concrete numbers.
What the Algorithm Does
The minimum-settlement algorithm takes all the individual payments in a group, figures out each person's net position (how much they're owed or how much they owe), and then finds the fewest possible transfers to zero everyone out.
Instead of "each person pays back each person they borrowed from," it asks: "ignoring the history of who paid what, what's the smallest number of transfers that balances everyone?"
The answer turns out to always be at most N−1 transfers for a group of N people.
The Problem It Solves: A 4-Person Example
Say four people — A, B, C, and D — take a trip together. Here's what each person paid for:
| Paid by | Item | Amount |
|---|---|---|
| A | Lunch (everyone) | $55 |
| B | Transportation (everyone) | $20 |
| C | Dinner (everyone) | $80 |
| D | Accommodation (everyone) | $145 |
Total: $300. Split four ways: $75 each.
Traditional One-to-One Settlement
In a naive approach, each person pays back each person they owe directly. With four people all paying for different things, this creates a web of up to 12 separate transfers. Some money even makes a round trip — A receives from B, then turns around and sends to C. Those intermediate hops are wasteful, especially when payment apps charge transaction fees.
With the Minimum-Settlement Algorithm
First, calculate each person's net position — how much they overpaid or underpaid relative to their fair share:
| Person | Amount fronted | Fair share | Net position |
|---|---|---|---|
| A | $55 | $75 | −$20 (owes) |
| B | $20 | $75 | −$55 (owes) |
| C | $80 | $75 | +$5 (owed to) |
| D | $145 | $75 | +$70 (owed to) |
Now, match the person who owes the most with the person who's owed the most, and so on:
- B (−$55) → D (+$70): B sends $55 to D. B is done. D's remaining balance: +$15.
- A (−$20) → D (+$15): A sends $15 to D. D is done. A's remaining balance: −$5.
- A (−$5) → C (+$5): A sends $5 to C. Everyone is at zero.
Total: 3 transfers — a 75% reduction from the 12 that one-to-one settling would require.
Why This Always Works
The algorithm works because of a simple mathematical guarantee: in any group where everyone splits a shared total, the sum of all "owed" amounts exactly equals the sum of all "owes" amounts. The books balance by definition.
Because the totals always match, you can always clear the largest outstanding debt in a single transfer — and each transfer eliminates at least one person from the equation. For N people, you never need more than N−1 transfers.
In practice, the number is often even lower. If two people's net positions happen to cancel each other out exactly, they settle directly and both drop out immediately.
| Group size | One-to-one max | Minimum-settlement max |
|---|---|---|
| 4 people | 12 transfers | 3 transfers |
| 6 people | 30 transfers | 5 transfers |
| 10 people | 45 transfers | 9 transfers |
WariSaku's Settlement view runs this calculation automatically and displays the result — who sends what amount to whom. No manual math needed.
Frequently Asked Questions
Q: What if the split isn't equal?
The algorithm works the same way. Weighted splits (where some members pay more or less than others) just change the "fair share" numbers used to compute each person's net position. After that, the same logic applies.
Q: What about rounding?
When amounts don't divide evenly, WariSaku applies your group's rounding setting (to the nearest cent, $1, $5, or $10) before calculating the settlement. This can adjust some net positions by a small amount, but the algorithm still minimizes transfers within those rounded amounts.
Q: Does the order of transfers matter?
No. The algorithm specifies who sends what to whom, but not the sequence. Everyone can transfer simultaneously, or in any order — the end result is the same.
Q: Does it work if someone pays for a subset of the group?
Yes. Each expense in WariSaku lets you specify which members it covers. The algorithm accounts for this — the net position for each member only reflects expenses they were part of.
Wrap-Up
The minimum-settlement algorithm turns a potentially messy web of transfers into the smallest possible set of direct payments. For a group of four, you're looking at a maximum of three transfers. For a group of ten, nine — compared to forty-five if everyone settled one-to-one.
The math is handled automatically in WariSaku's Settlement view. All you need to do is log the expenses and read the result.
