Stepping back for a moment, I suggest not using the tree at all. The last time I had to deal with a similar problem, I started with a tree, but later switched to an array.
The reasons for multiple, but number one reasons were performance, my classes are up to 100 or so, children could actually work better by manipulating them as an array than through tree nodes, mainly due to hardware locality and processor prefetching logic, and pipelining CPU processing
Thus, although the structure of an array algorithmically requires more N operations than a tree, performing these dozens of operations is likely faster than chasing pointers in memory.
Robert Gould
source share