Who owes who money optimisation problem

Posted by Francis on Stack Overflow See other posts from Stack Overflow or by Francis
Published on 2010-12-29T13:48:40Z Indexed on 2010/12/29 13:54 UTC
Read the original article Hit count: 185

Filed under:
|
|
|
|

Say you have n people, each who owe each other money. In general it should be possible to reduce the amount of transactions that need to take place. i.e. if X owes Y £4 and Y owes X £8, then Y only needs to pay X £4 (1 transaction instead of 2).

This becomes harder when X owes Y, but Y owes Z who owes X as well. I can see that you can easily calculate one particular cycle. It helps for me when I think of it as a fully connected graph, with the nodes being the amount each person owes.

Problem seems to be NP-complete, but what kind of optimisation algorithm could I make, nevertheless, to reduce the total amount of transactions? Doesn't have to be that efficient, as N is quite small for me.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about optimization