A Node.js + Express + MongoDB backend that predicts the winner and runner-up among a set of players using two algorithms: Tournament (Divide & Conquer) and Two-Scan (Iterative).
This project is perfect for exploring algorithm optimization, data modeling with MongoDB, and backend API development.
- Generate random players with random scores.
- Add players manually (name + score).
- View all players.
- Delete all players.
- Simple iterative approach.
- Finds winner and runner-up.
- Compares all remaining players →
2n - 3comparisons.
- Recursive approach for fewer comparisons.
- Tracks players defeated by the winner to determine runner-up.
- Comparisons closer to theoretical minimum:
n + log2(n) - 2.
- Tracks the number of comparisons made by each algorithm.
- Useful for algorithm performance analysis.
- Node.js + Express for REST API.
- MongoDB Atlas for persistent player storage.
- CORS enabled for frontend integration.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/players |
Get all players |
| POST | /api/players |
Add a new player |
| POST | /api/players/generate |
Generate random players |
| DELETE | /api/players |
Delete all players |
| POST | /api/run/two-scan |
Run Two-Scan algorithm |
| POST | /api/run/tournament |
Run Tournament (Divide & Conquer) algorithm |
- Iteratively find the maximum score → winner.
- Remove winner and find next maximum score → runner-up.
- Total comparisons:
2n - 3.
- Recursively divide players into pairs.
- Compare pairs and propagate winners upward.
- Track players defeated by the winner to find runner-up.
- Total comparisons:
n + log2(n) - 2(theoretical minimum).