Imagine a weekend cabin trip with five friends:
- Alice pays $300 for groceries.
- Bob pays $500 for the cabin reservation.
- Charlie pays $150 for gas and highway tolls.
- Dana pays $200 for ski lift passes.
- Eli pays $50 for firewood and snacks.
If every person paid everyone back individually for their proportional share, the group would face 10 distinct transactions:
$$\frac{N \times (N - 1)}{2} = \frac{5 \times 4}{2} = 10 \text{ payments}$$
People would spend hours sending $12.50 here and $34.20 there across peer-to-peer payment apps.
The Minimum Cash Flow Algorithm Explained
To split your bills easily without payment chaos, YourHissa uses a greedy graph simplification algorithm that reduces the network to at most $N - 1$ payments (in this case, 4 transactions instead of 10).
Here is how the algorithm works step-by-step:
Step 1: Calculate Net Balance for Every Participant
For each participant $i$, we compute the total amount paid minus their fair share:
$$\text{Net Balance}_i = \sum \text{Paid by } i - \sum \text{Share owed by } i$$
- A positive balance indicates a creditor who is owed money.
- A negative balance indicates a debtor who owes money.
- The sum of all net balances across the entire group always equals exactly zero.
Step 2: Sort Debtors and Creditors
The algorithm identifies:
- The person with the maximum debt (largest negative balance).
- The person with the maximum credit (largest positive balance).
Step 3: Execute Settlement and Reduce
A single transaction is scheduled between these two individuals for:
$$\text{Transfer Amount} = \min(|\text{Max Debt}|, \text{Max Credit})$$
This single transfer completely zeroes out either the debtor or the creditor.
Step 4: Recursive Termination
The algorithm repeats until all balances reach $0.00. For an $N$-person group, this takes at most $N - 1$ steps, drastically simplifying group settlements.