This project implements the Ranked Pairs voting algorithm to determine the winner of an election based on voter preferences.
The system records ranked votes, builds a pairwise preference matrix, sorts candidate pairs by strength of victory, and constructs a directed graph while preventing cycles to determine the final winner.
Click the thumbnail below to watch the program demonstration.
- Dynamic number of candidates and voters
- Pairwise preference matrix construction
- Ranked Pairs (Tideman) voting algorithm implementation
- Cycle detection using Depth First Search (DFS)
- Graph-based winner determination
- Modular and scalable C++ implementation
3
3
Alice
Bob
Charlie
Alice Bob Charlie
Bob Charlie Alice
Charlie Alice Bob
Let:
C = number of candidates
V = number of voters
| Operation | Complexity |
|---|---|
| Recording votes | O(V * C²) |
| Creating pairs | O(C²) |
| Sorting pairs | O(C² log C) |
| Locking pairs | O(C³) |
| Finding winner | O(C²) |
Overall complexity → O(V * C² + C³)
- C++
- Standard Template Library (STL)
- vector
- unordered_map
- Graph Algorithms
- Depth First Search (DFS)
Compile the program
g++ ranked_voting_system.cpp -o voting
Run the program
./voting (Linux / Mac)
voting.exe (Windows)
Run using sample input
./voting < sample_input.txt
ranked-voting-system
│
├── ranked_voting_system.cpp # Main program
├── sample_input.txt # Example test input
└── README.md # Project documentation
This project implements the Ranked Pairs (Tideman) voting algorithm. Steps
- Record voter preferences
- Build a pairwise preference matrix
- Create candidate pairs based on victories
- Sort pairs by strength of victory
- Lock pairs while preventing cycles
- The candidate with no incoming edges in the graph is declared the winner
Future enhancements that could be added:
- GUI based voting interface
- File-based input for large elections
- Visualization of the voting graph
- Support for large-scale voting datasets
Jaanvi Vohra
This project is open-source and available for educational and learning purposes.
