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
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
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.
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 dondod...@gmail.com 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
How come it just reversed the root? I still dont get it!
Rahul
On Feb 9, 7:57 pm, Don dondod...@gmail.com 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
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 menonrahul1...@gmail.com wrote:
How come it just reversed the root? I still dont get it!
Rahul
On Feb 9, 7:57 pm, Don dondod...@gmail.com wrote:
What about just the root being reversed?
Why is it different only in case of root?
Rahul
On Feb 9, 10:52 pm, Don dondod...@gmail.com 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
@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 of
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 ankitsamb...@gmail.comwrote:
Here the required program :
void findkthSmallest(Node *root,int k)
{
Node *stack[100];
int top=-1,count=0;
i think sunny's method should work.
On Sat, Jul 30, 2011 at 12:45 PM, varun pahwa varunpahwa2...@gmail.comwrote:
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 ankitsamb...@gmail.comwrote:
Here
would it work
temp=root;
for(int i=0;ik;i++)
{
temp=temp-left;
}
On Jul 29, 10:48 am, sunny agrawal sunny816.i...@gmail.com 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
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 narayan.shiv...@gmail.comwrote:
would it work
temp=root;
for(int i=0;ik;i++)
{
temp=temp-left;
}
On Jul 29, 10:48 am, sunny agrawal sunny816.i...@gmail.com wrote:
Node* x
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
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;
Iterative inorder of tree till you have traversed k elements. Last
element is the kth smallest.
On Jul 29, 10:10 am, AMAN AGARWAL mnnit.a...@gmail.com wrote:
Please tell the solution of this question
Given a Binary Search Tree, write a program to print the kth smallest
element without using
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 ase.as...@gmail.com wrote:
Iterative inorder of tree till you have traversed k elements. Last
element is the kth smallest.
On Jul 29, 10:10 am, AMAN
16 matches
Mail list logo