A Java implementation of three different election algorithms: Plurality, Runoff (instant-runoff voting), and Tideman (ranked pairs / Condorcet method).
This project demonstrates object-oriented design by implementing three distinct voting methods in a clean, modular architecture.
Plurality Election
- Single-choice voting system
- Winner: candidate with most votes
- Time: O(n), Space: O(m)
Runoff Election
- Ranked-choice voting with elimination rounds
- Winner: first candidate with >50% of votes
- Time: O(n·m²), Space: O(n·m)
Tideman Election
- Ranked pairs method with pairwise comparisons
- Uses DFS cycle detection to build preference graph
- Determines Condorcet winner if exists
- Time: O(m² + p·m²), Space: O(m² + p)
src/election/
├── Main.java # Entry point
├── algorithm/
│ ├── Plurality.java
│ ├── Runoff.java
│ └── Tideman.java
└── util/
├── InputUtil.java # Ballot collection & validation
└── OutputUtil.java # Formatting
bin/ # Compiled classes
Compile:
mkdir -p bin && find src -name "*.java" -print0 | xargs -0 javac -d binRun:
java -cp bin election.MainVS Code: Press F5
- Select election method (1-3)
- Enter candidate names (space-separated)
- Cast ballots:
- Plurality: single ID per vote
- Runoff/Tideman: space-separated IDs in preference order (e.g.,
0 1 2)
- View results and algorithm details
- OOP: Inner classes (Candidate, Pair), proper encapsulation
- Data Structures: ArrayList, HashMap, 2D arrays for matrices
- Features: Input validation, duplicate detection, user feedback, cycle detection
- Complexity: Analyzed and optimized for each algorithm
- Converted from procedural C to OOP Java
- Dynamic collections instead of fixed arrays
- Enhanced validation and error handling
- Better user experience with formatted output
- Graph algorithms (DFS) for cycle detection