Re: [algogeeks] Re: Binary Search Tree Question

2012-02-11 Thread praveen raj
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] Re: Binary Search Tree Question

2012-02-10 Thread sid1
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

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Don
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.

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Rahul Menon
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

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Rahul Menon
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

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Don
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:

[algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread Rahul Menon
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

Re: [algogeeks] Re: Binary Search Tree Question

2012-02-09 Thread atul anand
@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

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-30 Thread varun pahwa
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;

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-30 Thread Tushar Bindal
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

[algogeeks] Re: binary search tree question!!!!

2011-07-29 Thread shiv narayan
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

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-29 Thread sukhmeet singh
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

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-29 Thread Poised~
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

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-29 Thread ankit sambyal
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;

[algogeeks] Re: binary search tree question!!!!

2011-07-28 Thread noobcoder
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

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-28 Thread sunny agrawal
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