I have a bunch of objects that I am not sure on how to represent in order to maximize memory occupancy and possibly avoiding large CPU overhead. The most natural way to see it is as a tree. A picture is worth a thousand words As you can see, at each layer there are many nodes that are equal. Each tree node contains an object that I simply represented as an integer. Also, between each node of the tree, there are a bunch of other objects, represented by the $ L_x$ values on the arrows; all the $ L_x$ values between the same pair of layers are equal.
In an effort to improve memory occupancy, I simplified the data structure using a linked list, like show in the image below
So, each node of the new list can be of two types, let’s say
Aggregate node contains the tree nodes, each of which may be connected to one or more other tree nodes. It also contains a
label, which is not shown in the picture.
There may be cancellation on the tree depending on specific parameters of the tree node. To put it simply, if and only if two aggregate nodes have the same
label, a cancellation between the inner tree nodes may happen. For example, it may happen that nodes 1 and 8 of the tree node has the same
label and cancels-out: the path leading from 1 to 8 must be deleted (so both 1-4-8 and 1-6-8). However, how can I keep track of this cancellation in the new linked list?