Akinator
algorithms
game mechanics
AI in games
decision trees

What kind of algorithm is behind the Akinator game?

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

Akinator is an online game and mobile app where a "genie" attempts to guess the character the player is thinking of by asking a series of questions. The success of Akinator hinges on its intelligent use of machine learning algorithms and an underlying structure that continually adapts to player responses. This article will delve into the core algorithmic principles that empower Akinator, emphasizing decision trees, heuristics, and database efficiency.

Technical Explanation

Decision Trees and 20 Questions

At its core, Akinator functions similarly to a game of "20 Questions." The game starts with broad inquiries and narrows down choices based on user responses. The backbone of this questioning strategy is a decision tree, a model decision-making process that maps out possible outcomes.

  • Decision Tree Structure:
    • A decision tree is a flowchart-like structure with nodes representing questions (logical tests) and branches representing the outcomes of these questions. This continues until a final node or leaf is reached, which represents a prediction or classification.
    • For Akinator, each node represents a characteristic or question that refers to the character's specifics. Branching corresponds to user responses (yes, no, don't know).

Example of a Decision Tree:

Consider a simplified decision tree used by Akinator to identify a character:

  • Heuristic Evaluation:
    • Heuristics within Akinator measure the tree's prediction certainty. Scores are assigned based on response effectiveness and direct subsequent questioning.
    • These heuristic scores help prioritize questions that have historically narrowed down possibilities most effectively.
  • Similarity Matching: Akinator uses a database of user interactions (questions and answers) to identify patterns and characteristics common to certain characters. If a sequence of answers aligns closely with past patterns leading to a character guess, that guess becomes increasingly prioritized.
  • Data Aggregation: Aggregate data from users provides a data-driven backbone, helping the genie optimize guessing strategies.
  • Inverted Indexes: These are used to facilitate quick lookups of characters based on traits. This kind of structure supports fast retrieval times, crucial for maintaining the game's pace.
  • Efficient Querying: Database queries are optimized for rapid iteration over possible matches, leveraging indexing and caching strategies.

Related reading
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
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

All Rights Reserved.