Given a BST, find all sequences of nodes, that will generates the same bst.

Given a Binary Search Tree, generate all the sequences which would create the same binary search tree.

For eg: if bst is

  5
 / \
3   7

then output:

5 3 7

5 7 3

If bst is:

      5
    /   \
   4     7
  /     / \
 1     6   10

then output:

5 4 1 7 6 10

5 4 7 1 6 10

5 4 7 6 1 10

5 4 7 6 10 1

5 7 4 1 6 10

and so on…

Any help to solve such question Recursively.

the first tree is not a BST as 3 cannot have a left child that is greater than 3.
It should be like
5
/
3 7

thanks, I have corrected it now.

I have written a solution here. http://stackoverflow.com/questions/21211701/given-a-bst-and-its-root-print-all-sequences-of-nodes-which-give-rise-to-the-sa/24398114#24398114