A console-based C implementation designed to minimize the number of financial transactions required to settle outstanding debts among a group of participants, featuring dynamic multi-currency conversion and transaction processing fees.
In real-world peer-to-peer (P2P) systems, expense sharing platforms, and banking clearinghouses, entities frequently exchange funds, generating a complex web of mutual credits and debts. Settling each balance individually is inefficient and results in unnecessary platform fee overhead.
This project uses a Greedy Choice Heuristic and Two-Pointer settlement walk to find the minimum number of payments required to settle all debts. It converts foreign transactions (INR, EUR, GBP) into base USD using static exchange rates, applies a simulated 2% transaction fee, computes net balances, and prints the optimal settlement transactions.
Design and implement an advanced Financial Settlement Optimization System that minimizes the number of transactions required to settle debts among multiple banks or entities located across different regions, each possibly supporting different payment methods and currencies.
The program must:
- Input
$N$ participants and$T$ transactions. - Read transaction details:
from,to,amount, andcurrency. - Convert foreign currencies to USD and deduct a 2% platform fee from each transaction.
- Calculate net balances and split participants into debtors and creditors.
- Compute and display the minimal transactions required to achieve settlement.
- ๐ Multi-Currency Conversion: Seamlessly handles transactions in
USD,INR,EUR, andGBP. - ๐ Simulated Platform Fees: Deducts a 2% platform fee from every raw transfer to match real-world banking clearing rules.
- โก Greedy Optimization Engine: Pairs the largest debtor with the largest creditor to resolve the network in minimal steps.
- ๐ก๏ธ Floating-Point Stability: Utilizes
#define EPSILON 1e-9checks to handle decimal precision limits safely without infinite loops. - ๐ Extensive Reporting: Centralized project files, including execution reports and screenshots.
The project maps financial entities as nodes and transaction values as weighted directional links:
-
Net Balance Calculation:
$$\text{Balance}[i] = \sum \text{Received}[i] - \sum \text{Sent}[i]$$ -
Subset Division:
-
Creditors: Entities with balance
$> \text{EPSILON}$ -
Debtors: Entities with balance
$< -\text{EPSILON}$
-
Creditors: Entities with balance
-
Sorting:
- Sort creditors in descending order (largest credit first) using custom casting comparators in
qsort. - Sort debtors in ascending order (most negative debt first).
- Sort creditors in descending order (largest credit first) using custom casting comparators in
-
Greedy Matching:
- Settle by the minimum of the debtor's absolute liability and the creditor's balance.
- Decrement/increment balances by the settled amount.
- Shift list index pointers once a balance falls below
EPSILON. - Repeat until all lists are completely walked.
Transactionstruct: Stores sender index (from), receiver index (to), transaction amount, and currency string.Participantstruct: Stores entity ID (id) and the computed net balance (balance).- Arrays: Fast, contiguous storage for active transactions and active participants.
qsort: QuickSort from the C standard library (stdlib.h) is used to sort debtors and creditors using custom pointer-casting comparator functions.
-
Time Complexity:
-
Input Parsing:
$\mathcal{O}(T)$ where$T$ is the number of transactions. -
Sorting:
$\mathcal{O}(N \log N)$ where$N$ is the number of participants. -
Settlement Loop:
$\mathcal{O}(N)$ since at least one participant is fully settled in each step. -
Total Time Complexity:
$\mathcal{O}(T + N \log N)$
-
Input Parsing:
-
Space Complexity:
-
$\mathcal{O}(N + T)$ to hold participant records and the transaction journal.
-
global-debt-settlement-optimizer/
โโโ README.md # Project documentation
โโโ LICENSE # MIT License
โโโ .gitignore # Excludes binary executables
โโโ Makefile # Automation script for compilation
โโโ CONTRIBUTING.md # Pull request and style guidelines
โโโ CODE_OF_CONDUCT.md # Community behavior standards
โโโ CHANGELOG.md # Versioning log
โ
โโโ src/
โ โโโ project1.c # C source code
โ
โโโ docs/
โ โโโ DSA_Question.pdf # Original project prompt sheet
โ โโโ Project1_Report.pdf # Complete project report
โ
โโโ screenshots/ # Visual records of program execution
โโโ debt_optimizer_circular.png
โโโ debt_optimizer_multi_currency.png
โโโ debt_optimizer_normal.png
โโโ debt_optimizer_zero_tx.png
You need a C compiler (gcc) and make installed on your system.
Open your terminal in this directory and run:
# Using Makefile
make compile
# Or compile manually using GCC
gcc src/project1.c -o project1.exe -lmRun the compiled binary executable:
# Windows PowerShell
.\project1.exe
# Linux / macOS
./project1.exeEnter number of participants: 4
Enter number of transactions: 5
Enter transactions (from to amount currency)
0 1 100 USD
1 2 200 INR
2 3 50 EUR
3 0 20 USD
1 3 70 GBP
Optimized Transactions:
0 -> 3 : 78.40 USD
2 -> 3 : 45.08 USD
2 -> 1 : 6.47 USD
All debts settled using minimum transactions.
- Cyclic Debt Removal: Add graph traversal (DFS/Tarjan's) to identify and collapse circular dependencies before calculating net balances.
- Persistent Storage: Add file I/O to read input from a CSV ledger or database.
- Web UI visualization: Build a lightweight interactive network graph dashboard showing nodes (participants) and directed edges (transfers) using React & D3.js.
- Gained hands-on experience applying a Greedy choice strategy to solve NP-complete related network simplifications.
- Developed robust knowledge of C standard library sorting routines and custom comparator casts.
- Understood and corrected floating-point arithmetic limitations in C using epsilon bounds.
- Practiced clean software design patterns, decoupling directories for code, docs, and assets.
- Name: Renu K G
- Institution: Bapuji Institute of Engineering and Technology, Davanagere
- Program: Technology Orientation Program (TOP 4.0) โ COHORT
- Submission Date: March 14, 2026
This project is licensed under the MIT License.



