Akinator
algorithm
game mechanics
artificial intelligence
decision tree

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:

  1. First question: Is your character real? If yes, it continues with questions about real-life attributes.
  2. Second question: Is your character an actor?
  3. 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:

  1. Does this character have wings?
    • Yes: it is the dragon.
    • No: continue.
  2. 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.

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.

AspectDetails
Core AlgorithmDecision Tree
Supplementary TechniquesMachine Learning, Adaptive Learning
Question StructureBinary, probabilistically determined for optimal pruning
Data HandlingDynamic learning from user input
Key ChallengesEfficient data management, question prioritization
Prospective EnhancementsDeep learning, API integration, broader character database

Possible improvements

  1. Deep learning could let the game recognize patterns in non-binary inputs.
  2. A broader character database, from crowd-sourced knowledge or knowledge graph APIs.
  3. Predictive analytics on early answers could anticipate engagement and choose more challenging questions to keep players interested.

Course
Intermediate
27 lessons
15 hours
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 course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design