How does Akinator work? The algorithm behind the game
Codemia Knowledge Hub ·
Akinator is built on a decision tree, enhanced with machine learning. It asks a series of yes/no questions, and each answer filters out candidates until it reaches a final guess. Learning from player interactions over time is what makes it feel uncannily accurate.
Akinator as a decision tree
A decision tree is a flowchart-like structure:
- Root node: the entire dataset.
- Internal nodes: attributes, which act as decision points (the questions).
- Leaf nodes: outcomes, which for Akinator are the characters or objects it guesses.
Akinator's tree has to be both expansive, to cover a huge range of characters, and efficient, to need as few questions as possible. Each question splits the possible outcomes into subsets. For example:
- First question: Is your character real? If yes, it continues with questions about real-life attributes.
- Second question: Is your character an actor?
- Third question: Has your character won an Oscar?
Each question splits the potential outcomes and shrinks the search space the algorithm has to consider. Questions work like branches: each is a node that leads to further nodes until a leaf, the final guess, is reached.
A three-character example
Say Akinator must pick between a knight, a king and a dragon:
- Does this character have wings?
- Yes: it is the dragon.
- No: continue.
- Does this character wield a sword?
- Yes: it could be the knight.
- No: it is most likely the king.
Is Akinator AI? The machine learning part
Beyond the tree, Akinator uses machine learning to improve its guesses:
- Data collection and training: every game adds a data point. When a new character is introduced, Akinator learns its distinguishing features from the questions asked and the answers given.
- Adaptive learning: it can recalibrate the weight of questions based on how players answer. A question that narrows the choices correctly more often than others may be asked earlier.
Why it is not a binary search
A binary search always divides the data into two equal parts, as when searching a sorted array. Akinator divides the search space unevenly, based on the probability or expected utility of each question. Its trees are also more complex than plain binary trees and may form multi-way splits based on historical data. The hard part is maintaining a dynamic data structure that gets the most information out of every question, which comes down to efficient data management and question prioritization.
| Aspect | Details |
| Core Algorithm | Decision Tree |
| Supplementary Techniques | Machine Learning, Adaptive Learning |
| Question Structure | Binary, probabilistically determined for optimal pruning |
| Data Handling | Dynamic learning from user input |
| Key Challenges | Efficient data management, question prioritization |
| Prospective Enhancements | Deep learning, API integration, broader character database |
Possible improvements
- Deep learning could let the game recognize patterns in non-binary inputs.
- A broader character database, from crowd-sourced knowledge or knowledge graph APIs.
- Predictive analytics on early answers could anticipate engagement and choose more challenging questions to keep players interested.
Related reading
- What machine learning algorithm for this simple optimisation?
- What machine learning benchmarks are out there?
- What parameter represents sigma in scikitleans Support Vector Machine?
- What preprocessing.scale do? How does it work?
- What major problems would I have if I use Raft Consensus Algorithm in 50+ pods?
- What makes table lookups so cheap?
- What language was RabbitMQ written in?
- What makes this a fixed-length list in Dart?
System design interview problems on this topic
- Design an E-commerce Recommendation System: solution and walkthrough
- Design an LLM Inference Service: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough
- Design ChatGPT: solution and walkthrough

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.