R
raylopez99
What's the best way of implementing a multi-node tree in C++? What I'm
trying to do is traverse a tree of possible chess moves given an intial
position (at the root of the tree). Since every chess position has
around 30 moves, it would mean every node of the tree would have 30
branches (on average), which in turn themselves would average about 30
branches each.
I can think of a variety of ways of implementing this, including a
series of linked lists all pointing to the same header node at the
root, but I would like to know if there's a practical 'best' way, since
the tree will be traversed often, and it must be traversed quickly.
There will be no additions to the tree besides making it grow bigger
(longer, as move moves are added in a sequence). Certain branches will
be pruned, but the tree does not have to be rebalanced after pruning
(meaning the pruned branches will be simply marked as pruned but can
stay where they are).
Ideally I would like something already found in the .NET Standard
Collection Classes or Generic Collection classes, which include:
SortedList (key/value collection) and KeyedCollection, which are kinds
of Sets/Maps it appears.
BTW, nearly every reference I look shows as the sole example of tree a
red-black binary tree, which is not that helpful to me, though I
realize probably as a mathematical matter you can parse any multnode
tree into a red-black binary tree.
Thanks,
RL
Refs:
http://en.wikipedia.org/wiki/Standard_Template_Library#Containers
http://en.wikipedia.org/wiki/Set_(computer_science)
trying to do is traverse a tree of possible chess moves given an intial
position (at the root of the tree). Since every chess position has
around 30 moves, it would mean every node of the tree would have 30
branches (on average), which in turn themselves would average about 30
branches each.
I can think of a variety of ways of implementing this, including a
series of linked lists all pointing to the same header node at the
root, but I would like to know if there's a practical 'best' way, since
the tree will be traversed often, and it must be traversed quickly.
There will be no additions to the tree besides making it grow bigger
(longer, as move moves are added in a sequence). Certain branches will
be pruned, but the tree does not have to be rebalanced after pruning
(meaning the pruned branches will be simply marked as pruned but can
stay where they are).
Ideally I would like something already found in the .NET Standard
Collection Classes or Generic Collection classes, which include:
SortedList (key/value collection) and KeyedCollection, which are kinds
of Sets/Maps it appears.
BTW, nearly every reference I look shows as the sole example of tree a
red-black binary tree, which is not that helpful to me, though I
realize probably as a mathematical matter you can parse any multnode
tree into a red-black binary tree.
Thanks,
RL
Refs:
http://en.wikipedia.org/wiki/Standard_Template_Library#Containers
http://en.wikipedia.org/wiki/Set_(computer_science)