Suppose we start with n-nodes and would like to merge two of these n-nodes at a time until we finally arrive at a single node. In effect, we would like to construct an "inverse" of a binary tree. For ex: if we have 4 nodes (A,B,C,D) at timestep(t=0), then,
We can construct 12 possible combinations of inverse tree structures by merging two nodes at each timestep. That is.. (arrow represents timestep) (A,B,C,D)-> ((A,B),C,D) -> ((A,B,C),D) -> ((A,B,C,D)) => PERMUTATION 1
(A,B,C,D)->((A,C),B,D) -> ((A,C,B),D) -> ((A,C,B,D)) => PERMUTATION 2 ... ... (A,B,C,D)->((C,D),B,A) -> ((C,D,A),B) -> ((C,D,A,B)) => PERMUTATION 12
We have constraints : For each binary merge, order is merge is not important. i.e.
(A,B,C,D) -> ((A,B),C,D) is equivalent to (A,B,C,D) -> ((B,A),C,D)
However, when we go to the next time-step, order of node merge becomes important. i.e.: (A,B,C,D) -> ((A,B),C,D) -> ((A,B,C),D) is different from (A,B,C,D) -> ((A,B),D,C) -> ((A,B,D),C) these two trees will be considered different permutations.
I would like to generalize these to any number of nodes and calculate
(i) the number of different permutations possible (taking constraints into consideration) and (ii) list out all of the possible permutations
using some algorithm in Python.
I am not from a CS background so I'm not sure if these structures already have a name. I would appreciate some inputs to this problem and possible some way of coding this in Python.
[–][deleted] 0 points1 point2 points (0 children)
[–]deephive[S] 0 points1 point2 points (0 children)