How greedy debt minimization collapses a tangled web of who-owes-who into the fewest possible transactions, with a worked example for five people.
If five people in a group end up owing each other twelve different amounts, you don't need twelve transfers. You need at most four. Here's the algorithm - explained without computer-science jargon.
Imagine a weekend trip with five friends - Alex, Beth, Chris, Dee, and Eli. Over three days, they pay for various things and end up with these net balances:
Alex +€90 (others owe Alex €90 in total) Beth +€40 Chris −€30 (Chris owes the group €30) Dee −€60 Eli −€40 Sum = 0 ✓
Positive numbers are creditors (people owed money). Negative numbers are debtors (people who owe). The total always sums to zero - that's the invariant we work with.
The naive approach is to track every individual debt: "Beth owes Alex €15 for the taxi", "Chris owes Beth €8 for groceries", and so on. By the end of the trip, you might have twelve or fifteen pairwise debts. Settling them all literally means twelve or fifteen transfers, each with its own friction.
Instead, we collapse everything into the net balances above and then run a simple loop:
Step 1. Largest debtor: Dee (−60). Largest creditor: Alex (+90). Smaller magnitude is 60.
Dee → Alex: €60 After: Alex +30 Beth +40 Chris −30 Dee 0 (settled, drop) Eli −40
Step 2. Largest debtor: Eli (−40). Largest creditor: Beth (+40). Smaller magnitude is 40.
Eli → Beth: €40 After: Alex +30 Beth 0 (settled, drop) Chris −30 Eli 0 (settled, drop)
Step 3. Largest debtor: Chris (−30). Largest creditor: Alex (+30).
Chris → Alex: €30 After: Alex 0 (settled) Chris 0 (settled) Done.
Three transfers, not twelve. Every debt is cleared, every balance is zero.
The minimum number of transfers needed to settle a set of balances with k non-zero participants is at most k − 1, and the greedy algorithm above always achieves that bound. (You can prove it by induction: each step zeroes at least one person, and the remaining balances still sum to zero.)
There's a more theoretical "minimum cash flow" formulation that partitions balances into exact zero-sum subsets - that can sometimes do better than greedy by a transfer or two when balances happen to match exactly. But it's NP-hard in the general case, and for groups smaller than 50 people the difference is rarely more than one transaction. Greedy is the right trade.
Three transfers vs twelve isn't just less typing - it's the difference between "we'll settle when we get home" and actually settling. The friction of paying someone €4 is the same as paying someone €40, and groups consistently leave small debts unsettled forever. Collapsing the chains means more transfers actually happen, and groups end the trip square instead of with a tail of "I'll get you next time"s.
Smart settlement turns "we owe each other a bunch of stuff" into "I owe Alex €30, you owe Beth €40, we're done."
Free forever. No signup. Works in your browser in 30 seconds.