I have an N-ary tree where each node contains some data and its children:
Node {
// data
Node[] children = new Node[30];
}
As you can see, the size of the children array is fixed to 30 regardless of the current number of descendants. The array can contain something like this:
null, null, someNode, null, anotherNode, ...
A tree like this is always incomplete; therefore, I can't serialize it as an array where c child is placed in N * i + 1 + c (being i the index of the parent node).
I can serialize the tree by preorder traversal using / symbol to represent null child, but this approach requires n*30*sizeOfData bytes. Even if I represent the absence of children by, for example, #, it will take n*30*sizeOfData - numberOfLeafs*29, which is too many.
If you know a better approach to serialize a tree like this please write me ;)
Thanks in advance.