I would say it depends on what you want to do with the data structure.
You can use the fact that Mathematica expressions themselves are trees.
If only leaf nodes are used, use nested lists, for example. {{1, {2, 3}}, 4} . If another node should also carry some data, you can use something like this:
tree[1][tree[2][a, b], tree[3][c, tree[4][d, e]]]
See the structure as follows:
{{1, {2, 3}}, 4} // TreeForm tree[1][tree[2][a, b], tree[3][c, tree[4][d, e]]] // TreeForm
The next question is how to implement algorithm X in such a data structure.
source share