Search code examples
treeartificial-intelligenceminimaxalpha-beta-pruning

Is it necessary to create a tree for the alpha-beta pruning algorithm?


I've seen implementations of the minimax and alpha-beta pruning algorithms on the web. These implementations use an array rather than a tree structure to generate the possible game movements.

Is it necessary to create a tree, using a structure with nodes, for these algorithms? Why using an array to store the game tree?


Solution

  • For alpha-beta / minimax and other related algorithms, it is not required to explicitly create a tree / store it in memory. You implicitly "traverse" a tree through recursive function calls, but never explicitly create one, and never need to store any data in any nodes of such a "tree".

    Given a game state, you only ever temporarily need a data structure to contain the legal moves or the successor game states from that state; something like an array / list is the most obvious data structure for that. You only need this temporarily such that you can loop through it and run your recursive function calls, afterwards you can throw them away again. You'll never have to store the complete tree.