What type of permutation tree

Associate
Joined
19 Jan 2011
Posts
658
Hi what type of permutation tree is this

A1
/ | \
B1 B2 B3
/ \ / \ / \
C1 C2 C1 C2 C1 C2

A1 B1 C1
A1 B1 C2
A1 B2 C1
A1 B2 C2
A1 B3 C1
A1 B3 C2

1x3x2 = 9 options

Currently got lots nested for loop's to work out all options
for (i=0,i < A[n], i++)
for (j=0,j < B[n], j++)
for (k=0,k < C[n], k++)
print A B[j] C[k]

I want something better though i just don't feel this is best way
thanks :)
 
1x3x2 = 9 options

late post hay ... 6 options right? :-).

What you described isn't exactly a typical data structure. A binary tree has two vertices and each node has one parent node except the root node.
An M-ary tree requires each node to have only one parent however a node can have many children.
The trouble is your nodes have two parents. You need a hybrid traversal of pre-order traversal (for binary tree) such that when the child has no vertices you go back to root and traverse undiscovered vertices instead of going to parent.

see: http://en.wikipedia.org/wiki/Tree_traversal

Unless your planning on having a tree structure and if your vectors are going to remain this small, it's just not worth the effort. At worst your algorithm is < O(N^3) (N cubed time) which would assume all A, B and C have the same length. At best if you build a hybrid traversal you may be able to obtain a much faster logarithmic time solution but like I said if your data is small, not worth the effort.
 
Yer 6 ! !
Thanks , this is just a example that is simplified I have 6 arrays that could have up to 1-3 options in each
I'll read up more and hopefully it will click
 
Back
Top Bottom