Simple Java Code to minimize redundant cash transactions. Simply Download the file. run SplitwiseTransaction main class.
- This project involves a Java Class which reads and parses input into a directed graph component.
- Each Edge between userA, userB denotes money userA paid for userB.
- The directed graph can handle multiple transactions between 2 users.
SplitwiseAlgorithm
: Run this file to get result. Involves main algorithm + Binding with helper classes.Constants
: General Constant VariablesCandidateInfo
: User Info mapping with Name + Id. Each Name is mapped to an unique ID.Node
: Node object denotes each Graph Node.
- Convert the JSon into a Adjacency List of users.
- Identify each user in a group in a debt or receiver of cash from people in a direct connected component with this friends.
- Distribute People in two separate groups i.e. Receivers + Senders
- Do a map traversal of these groups in a linear manner to identify
- If a receiver(money > 0) can send more money to any user to whom he owes.
- Repeat step 1 until he has a currency count > 0
- Also add this new dependency into the graph to mark this new connection
- At the end a new graph with newly connected nodes will be present.
- This directed graph gives clear picture of how much is owed by whom.
None