An interactive web application for learning and practicing Splay Trees - a self-adjusting binary search tree.
Try it here: https://splayer-game.netlify.app/
This project visualizes tree rotations in real time and challenges users to match a reference tree across multiple levels while tracking performance on a live leaderboard.
This application combines:
- A full implementation of a Splay Tree (insert, search, delete, and splay operations)
- Real-time tree visualization using Cytoscape.js
- A leaderboard with real-time updates (created via Firestore)
I struggled with Splay Trees. The different rotation cases felt easy to confuse when reading them statically on paper.
So I built Splayer to practice my skills and test my understanding of the data structure.
What started as a visualizer turned into a game with scoring and a leaderboard system. The backend is powered by Firebase and Firestore.
Building this helped me understand the data structure far better than passive study ever did.
The goal is simple:
Understand how splaying dynamically restructures a tree and how rotations change its shape.
Each level provides a predefined sequence of insertions that builds a reference tree.
You interact with your own tree using:
- Insert
- Search
- Delete
Every operation triggers a splay, moving the accessed node to the root through rotations.
Your objective is to match the structure of the reference tree exactly.
When both trees are structurally identical:
- The level is completed
- Points are awarded
- Your score is submitted to the leaderboard
- HTML5
- CSS3
- Vanilla JavaScript
- Cytoscape.js
- Firebase
- Firestore
The project includes a complete Splay Tree implementation:
Nodeclass (key, left, right, parent)rotateLeftrotateRightsplay- Zig
- Zig-Zig
- Zig-Zag
insertsearchdelete
Splaying moves recently accessed elements closer to the root.
Over a sequence of operations, this results in O(log n) amortized time complexity.
The leaderboard query orders by score and then by last-updated time:
score(descending)lastUpdated(ascending)
Firestore requires a composite index for this query. Until the index finishes building, the leaderboard page may show an error.
Contributions are welcome.
If you would like to improve the UI, add new levels, optimize the tree implementation, or enhance the leaderboard system, feel free to open an issue or submit a pull request.