SecureVote is a secure, efficient, and fair online voting system designed to demonstrate real-world application of fundamental data structures. The system provides a complete end-to-end voting solution with voter authentication, candidate selection, vote submission, and real-time result tallying.
The project simulates a real-world electronic voting scenario where:
- Registered voters can authenticate using their Government ID
- Voters can view all candidates and cast their vote
- Each voter can only vote once (preventing fraud)
- Votes are processed fairly in the order they are received
- Real-time results are displayed with vote counts and percentages
| Problem | Solution |
|---|---|
| Voter Identity Verification | Fast O(log n) lookup using AVL Tree ensures quick authentication even with millions of voters |
| Preventing Double Voting | Each voter's status is tracked in the tree; once voted, they cannot vote again |
| Fair Vote Processing | FIFO Queue ensures votes are counted in the exact order received - no vote gets priority |
| High Traffic Handling | Queue-based buffering decouples vote submission from processing, handling traffic spikes gracefully |
| Dynamic Candidate Management | Linked List allows easy addition/removal of candidates without memory reallocation |
| Scalability | Custom data structures avoid framework overhead, providing lightweight and efficient operations |
File: VoterBST.java
GOV005
/ \
GOV003 GOV007
/ \ / \
GOV001 GOV004 GOV006 GOV009
Why AVL Tree?
- O(log n) Search: When a voter logs in, their Government ID must be verified. With millions of voters, linear search O(n) would be too slow. AVL Tree guarantees O(log n) lookup.
- Self-Balancing: Unlike a regular BST that can degrade to O(n) with sorted inputs, AVL Tree maintains balance through rotations, ensuring consistent performance.
- Ordered Storage: Voters are stored sorted by Government ID, enabling efficient range queries if needed.
How It's Used:
- Registration: Voters are inserted into the tree during system initialization
- Login: When a voter enters their ID, the tree is searched to validate their identity
- Vote Status: Each voter node tracks whether they've voted, preventing double voting
Key Operations:
| Operation | Time Complexity | Description |
|---|---|---|
| Insert | O(log n) | Add new voter with automatic rebalancing |
| Search | O(log n) | Find voter by Government ID |
| Update | O(log n) | Mark voter as "has voted" |
File: VoteQueue.java
ENQUEUE β [Vote5] β [Vote4] β [Vote3] β [Vote2] β [Vote1] β DEQUEUE
(rear) (front)
Why Queue?
- Fairness: Votes are processed in exactly the order they're received - First In, First Out (FIFO)
- Decoupling: Separates vote submission (fast) from vote processing (can be slower), implementing the Producer-Consumer pattern
- Traffic Handling: During peak voting hours, the queue buffers incoming votes, preventing system overload
- Thread Safety: Synchronized operations prevent race conditions in concurrent environments
How It's Used:
- Vote Submission: When a voter casts their vote, it's immediately added to the queue (enqueue)
- Background Processing: A separate thread continuously processes votes from the queue (dequeue)
- Vote Counting: Each dequeued vote updates the respective candidate's count
Key Operations:
| Operation | Time Complexity | Description |
|---|---|---|
| Enqueue | O(1) | Add vote to rear of queue |
| Dequeue | O(1) | Remove and process vote from front |
| Peek | O(1) | View next vote without removing |
File: CandidateLinkedList.java
HEAD β [Elizabeth Warren] β [James Mitchell] β [Sarah Chen] β [Michael Rivera] β NULL
β β β β
Democratic Republican Independent Green Party
Why Linked List?
- Dynamic Size: Candidates can be added or removed without resizing arrays
- Memory Efficiency: Only allocates memory for actual candidates, no wasted space
- Ordered Traversal: Easy iteration to display all candidates or calculate results
- Simple Updates: Vote counts are stored in each node, easily incremented
How It's Used:
- Display Candidates: Traverse the list to show all candidates on the voting page
- Vote Counting: When a vote is processed, find the candidate and increment their count
- Results Calculation: Traverse to sum votes and calculate percentages
Key Operations:
| Operation | Time Complexity | Description |
|---|---|---|
| Add | O(1) | Add candidate at tail |
| Find by ID | O(n) | Search for specific candidate |
| Traverse | O(n) | Display all candidates or calculate results |
File: TreeNode.java
Each node in the AVL Tree contains:
- Voter Data: The voter object with ID, name, and voting status
- Left Child: Reference to left subtree (smaller IDs)
- Right Child: Reference to right subtree (larger IDs)
- Height: Used for AVL balance calculations
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β VOTER β β AVL TREE β β QUEUE β β LINKED LIST β
β LOGIN ββββββΆβ SEARCH β β β β β
β (Gov ID) β β O(log n) β β β β β
βββββββββββββββ ββββββββ¬βββββββ βββββββββββββββ βββββββββββββββ
β
ββββββββΌβββββββ
β VALID? β
ββββββββ¬βββββββ
β YES
ββββββββΌβββββββ βββββββββββββββ βββββββββββββββ
β SELECT β β ENQUEUE β β PROCESSOR β
β CANDIDATE ββββββΆβ VOTE ββββββΆβ THREAD β
β & SUBMIT β β O(1) β β (DEQUEUE) β
βββββββββββββββ βββββββββββββββ ββββββββ¬βββββββ
β
ββββββββΌβββββββ
β UPDATE β
β CANDIDATE β
β VOTE COUNT β
βββββββββββββββ
| Technology | Purpose |
|---|---|
| Java 8+ | Core programming language |
| HttpServer | Built-in Java HTTP server (com.sun.net.httpserver) |
| Custom Data Structures | AVL Tree, Queue, Linked List - no external libraries |
| Multi-threading | Background vote processor thread |
| Technology | Purpose |
|---|---|
| HTML5 | Semantic page structure |
| CSS3 | Modern styling with gradients, animations, glassmorphism |
| JavaScript (ES6+) | Dynamic UI, API calls, state management |
| Fetch API | Asynchronous HTTP requests to backend |
| Component | Description |
|---|---|
| RESTful API | JSON-based communication between frontend and backend |
| Single Page Application | Dynamic content updates without page reloads |
| Real-time Polling | Results update every 3 seconds |
| Responsive Design | Works on desktop and mobile devices |
voting/
βββ src/
β βββ model/ # Data Models
β β βββ Voter.java # Voter entity (ID, name, hasVoted)
β β βββ Candidate.java # Candidate entity (ID, name, party, votes)
β β βββ Vote.java # Vote entity (voterId, candidateId, timestamp)
β β
β βββ datastructures/ # Custom Data Structure Implementations
β β βββ VoterBST.java # AVL Tree for voter registry
β β βββ TreeNode.java # Node class for AVL Tree
β β βββ VoteQueue.java # FIFO Queue for vote processing
β β βββ CandidateLinkedList.java # Linked List for candidates
β β
β βββ service/ # Business Logic
β β βββ VotingSystem.java # Core voting operations
β β
β βββ server/ # HTTP Server
β βββ VotingServer.java # REST API endpoints
β
βββ web/ # Frontend
β βββ index.html # Main voting page
β βββ admin.html # Admin dashboard
β βββ css/
β β βββ styles.css # Styling
β βββ js/
β βββ app.js # Frontend logic
β
βββ README.md # This file
- Java JDK 8 or higher
- Web browser (Chrome, Firefox, Edge)
-
Compile the Java files:
cd src javac -d ../out server/VotingServer.java -
Run the server:
cd ../out java server.VotingServer -
Open the application: Navigate to
http://localhost:8080in your browser
Use these pre-registered Government IDs to test the system:
| Government ID | Voter Name |
|---|---|
| GOV001 | Alice Johnson |
| GOV002 | Bob Smith |
| GOV003 | Carol Williams |
| GOV004 | David Brown |
| GOV005 | Eva Martinez |
| GOV006 | Frank Wilson |
| GOV007 | Grace Lee |
| GOV008 | Henry Taylor |
| GOV009 | Ivy Anderson |
| GOV010 | Jack Thomas |
| Endpoint | Method | Description | Request Body |
|---|---|---|---|
/api/login |
POST | Validate voter ID | {"govId": "GOV001"} |
/api/vote |
POST | Submit a vote | {"voterId": "GOV001", "candidateId": "C001"} |
/api/results |
GET | Get current tally | - |
/api/candidates |
GET | Get candidate list | - |
/* |
GET | Serve static files | - |
| Operation | Data Structure | Time Complexity |
|---|---|---|
| Voter Lookup | AVL Tree | O(log n) |
| Voter Registration | AVL Tree | O(log n) |
| Vote Submission | Queue | O(1) |
| Vote Processing | Queue | O(1) |
| Candidate Search | Linked List | O(n) |
| Display Candidates | Linked List | O(n) |
| Calculate Results | Linked List | O(n) |
- β Secure voter authentication with O(log n) lookup
- β One vote per voter enforcement
- β Fair FIFO vote processing
- β Real-time result updates
- β Modern, responsive UI
- β No external frameworks - pure Java & vanilla JavaScript
- β Thread-safe concurrent operations
This project is created for educational purposes to demonstrate data structure implementations in a real-world application.