mirror of tree
PRAVEEN RAJ
DELHI COLLEGE OF ENGINEERING
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@goo
This function is not reversing the tree, it swapping the left and
right sub trees. for ex.
6
5 8
4 7 9
1 11
2
=>
6
8 5
9 4
111
@Rahul : if you check the flow properly ,(lets concentrate on the root node
, call other as left and right subtree) you will find that after done with
reversing root->left->left subtree , it reaches root(backtrack to root)
node and then swap root->left and root->right.
now because it is inorder way
What about just the root being reversed?
Why is it different only in case of root?
Rahul
On Feb 9, 10:52 pm, Don wrote:
> Because it reverses one side twice and the other side not at all.
> It does a lot of work to accomplish nothing.
> Don
>
> On Feb 9, 9:06 am, Rahul Menon wrote:
>
>
>
>
>
>
Because it reverses one side twice and the other side not at all.
It does a lot of work to accomplish nothing.
Don
On Feb 9, 9:06 am, Rahul Menon wrote:
> How come it just reversed the root? I still dont get it!
>
> Rahul
>
> On Feb 9, 7:57 pm, Don wrote:
>
>
>
> > It appears to be an attempt to
How come it just reversed the root? I still dont get it!
Rahul
On Feb 9, 7:57 pm, Don wrote:
> It appears to be an attempt to reverse the tree. However, there is a
> problem. It reverses the left sub-tree, then swaps the left and right
> sub-trees. Then it reverses the right sub-tree. But wait!
Thanks!
I knew that it wont reverse the tree but was not sure about how it
reversed just the root.
On Feb 9, 7:57 pm, Don wrote:
> It appears to be an attempt to reverse the tree. However, there is a
> problem. It reverses the left sub-tree, then swaps the left and right
> sub-trees. Then it rev
It appears to be an attempt to reverse the tree. However, there is a
problem. It reverses the left sub-tree, then swaps the left and right
sub-trees. Then it reverses the right sub-tree. But wait! The original
left sub-tree which we reversed is now the right sub-tree, so we
actually unreversed it.
i think sunny's method should work.
On Sat, Jul 30, 2011 at 12:45 PM, varun pahwa wrote:
> do morris traversal until you find k. but that may modify the tree if you
> break as you find k.
>
>
> On Sat, Jul 30, 2011 at 9:14 AM, ankit sambyal wrote:
>
>> Here the required program :
>>
>> void findk
do morris traversal until you find k. but that may modify the tree if you
break as you find k.
On Sat, Jul 30, 2011 at 9:14 AM, ankit sambyal wrote:
> Here the required program :
>
> void findkthSmallest(Node *root,int k)
> {
> Node *stack[100];
> int top=-1,count=0;
> Node *temp;
>
Here the required program :
void findkthSmallest(Node *root,int k)
{
Node *stack[100];
int top=-1,count=0;
Node *temp;
stack[++top]=root;
/*First we will find the minimum node*/
temp=root;
while(temp->left != NULL)
{
stack[++top]=temp->left;
temp->left=
The only way remains is to use the iterative method of traversing a BST in
in-order (you have to use a Stack to keep track of father).
The place where you print the value of the node, put a condition before that
if (!(--k)){
print value_of_node;
}
in the outermost loop where you check
"while(
no it wouldn't try finding a tree where no left exist in the root
On Fri, Jul 29, 2011 at 2:14 PM, shiv narayan wrote:
> would it work
> temp=root;
> for(int i=0;i {
> temp=temp->left;
> }
>
> On Jul 29, 10:48 am, sunny agrawal wrote:
> > Node* x = TREE_MINIMUM(root);
> > for(int i = 0; i <
would it work
temp=root;
for(int i=0;ileft;
}
On Jul 29, 10:48 am, sunny agrawal wrote:
> Node* x = TREE_MINIMUM(root);
> for(int i = 0; i < k-1; i++){
> x = TREE-SUCCESSOR(x);}
>
> return x;
>
>
>
>
>
>
>
>
>
> On Fri, Jul 29, 2011 at 11:08 AM, noobcoder wrote:
> > Iterative inorder of tree til
Node* x = TREE_MINIMUM(root);
for(int i = 0; i < k-1; i++){
x = TREE-SUCCESSOR(x);
}
return x;
On Fri, Jul 29, 2011 at 11:08 AM, noobcoder wrote:
> Iterative inorder of tree till you have traversed k elements. Last
> element is the kth smallest.
>
> On Jul 29, 10:10 am, AMAN AGARWAL wrote:
> >
Iterative inorder of tree till you have traversed k elements. Last
element is the kth smallest.
On Jul 29, 10:10 am, AMAN AGARWAL wrote:
> Please tell the solution of this question
>
> Given a Binary Search Tree, write a program to print the kth smallest
> element without using any static/global
16 matches
Mail list logo