# Thread: doubling tree

1. ## doubling tree

Hi,
I would really appreciate any help on this.

Doubling tree is a problem where a duplicate node is inserted as a left child for each node in a binary search tree.

This code works:
Code:
```void doubleTree(root)
{
if(root == NULL) return;
else
{
doubleTree(root->LeftChild);
doubleTree(root->RightChild);

...
.....
<create a new node and insert as the left child with data field of the node same as node>
}
}```
but this doesnt: ????????
Code:
```void doubleTree(root)
{
if(root == NULL) return;
else
{
...
.....
<create a new node and insert as the left child with data field of the node
same as node>

doubleTree(root->LeftChild);
doubleTree(root->RightChild);

}
}```
Shouldnt it work??

2. Nope. You'd get stack overflow because root->LeftChild is the node you just inserted, so you'd keep infinitely recursing to the node you just inserted.

3. thnks a lot for the explanation.

one more doubt...does recursion in a binary search tree lead to top-bottom or bottom - top traversal, or can it be both ??

4. That's kind of an odd follow-up question. Is this for homework?

The fact that you don't know the answer shows that you don't understand recursion, or traversal of binary trees... I'm not sure that just giving you answers is going to help you any.

5. Originally Posted by gunner4life
Hi,
I would really appreciate any help on this.

Doubling tree is a problem where a duplicate node is inserted as a left child for each node in a binary search tree.

This code works:
Code:
```void doubleTree(root)
{
if(root == NULL) return;
else
{
doubleTree(root->LeftChild);
doubleTree(root->RightChild);

...
.....
<create a new node and insert as the left child with data field of the node same as node>
}
}```
but this doesnt: ????????
Code:
```void doubleTree(root)
{
if(root == NULL) return;
else
{
...
.....
<create a new node and insert as the left child with data field of the node
same as node>

doubleTree(root->LeftChild);
doubleTree(root->RightChild);

}
}```
Shouldnt it work??
sry consider me noob....but i wanted to ask

Is the order of insertion in the above case top-bottom?? its evident that the tree traversal is top-bottom...

6. bounce!!!!

7. I think the phrase you're looking for is "bump" and hey, don't do it.

Popular pages Recent additions