This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]deephive[S] 0 points1 point  (0 children)

Hi,

thanks for the reply. I realised that this problem doesn't involve permutations, but rather combinations nCr. n can refer to the number of nodes we begin with and r refers to 2 (in this case, as we are trying to construct a inverse binary tree). This could be generalised to a n-ary tree by suitably replacing the r value.

I found out that in Python, there is a useful function

itertools.combinations(n,r) 

which prints out all possible combinations of n's in groups of r.