0

I am working on this project where I am required to find the theoretical proof for following.

I have a particular type of binary trees, where

1) each internal node will definitely have two children.

2) There are n leaf nodes and can be assumed in order 1 to n from left most to right most.

Now this is clear that there would be exponential number of such possible trees which have theses two properties.

If I start from any random tree and randomly sample one of the internal node perform one of the two operations Left Rotate or Right Rotate (https://en.wikipedia.org/wiki/Tree_rotation), randomly. Is it possible to start from any random to tree to any other tree in the search space.

I have tried various resources but couldn't find any proof for it. I have tried it myself but not able to reach to a solution. I'd be glad if someone can help me out here.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
Naman
  • 2,569
  • 4
  • 27
  • 44
  • I'm voting to close this question as off-topic because it is not a programming question. – Raymond Chen Sep 17 '15 at 00:26
  • Could you please suggest as what is the right place on stackoverflow to ask these kind of questions? Because I tried to include the tags which seemed relevant to me. – Naman Sep 17 '15 at 19:42
  • This doesn't belong on StackOverflow at all, since it's not a programming question. Try http://cs.stackexchange.com/ – Raymond Chen Sep 17 '15 at 20:05

1 Answers1

1

First show that all trees with same number of leaf nodes have same number of internal nodes. That is shown by checking how many leaf nodes has a tree with I internal nodes. With I internal nodes, there are 2*I edges. I-1 of these edges connects internal nodes, so I+1 edges are left for leaf nodes. So, tree with n leaf nodes, has n-1 inner nodes.

To see that one tree can be transformed to the other tree, it is enough to transform both trees to some 'base' tree. E.g. let A be tree where every internal node (except last) has on left side leaf and on right side internal node. It is more like a path :-) To transformed any tree to A only right rotations are needed, and that is easy to find order nodes how to do rotations. To transform T1 to T2 it is enough to transform T1 to A, and than by reverse list of rotations A to T2.

Ante
  • 5,350
  • 6
  • 23
  • 46
  • I guess, this seems good to me. I have been thinking along the same lines. Now I think I still need to prove that A can be transformed to a left path tree by performing right rotations on all internal node that can be right rotated. It seems very intuitive but still need to find the proof. – Naman Sep 21 '15 at 20:30
  • I guess, could I do that by mathematical induction? – Naman Sep 21 '15 at 20:45
  • 1
    Yes. If leftmost leaf is on depth k, then with k-1 rightrotations it will be on depth 1, and right subtree of root is problem of size n-1 (induction step) – Ante Sep 22 '15 at 05:46