Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What algorithms exist to minimize the number of transactions between nodes in a graph?

That title probably doesn't make sense. Assume the following:

  • A owes B $5
  • C owes B $10
  • B owes D $15

In this basic situation there are three transactions but it can be reduced to two transactions:

  • A gives D $5
  • C gives D $10

Given a much more complicated graph, what algorithms exist to minimize the total number of transactions?

like image 766
knpwrs Avatar asked Sep 12 '13 18:09

knpwrs


1 Answers

It seems to me the first thing you have to figure out how much each person is up/down after all transactions take place. For your example, that would be:

A :  -5
B :   0
C : -10
D : +15

Once you have that, you just have to make them all zero. Take your highest gain, and start adding losses to it. At this point it's basically a bin-packing problem.

like image 134
Geobits Avatar answered Nov 03 '22 09:11

Geobits