Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@atul: can you explain what this is doing? for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } when u do tree reversal I see that child points to parent( basically direction reversed). Now if 1 /|\ 234 //\ 5 6 7 /\ 89 in the last iteration along leftmost path , pointer to 8 is returned(pre) whose child is then assigned as 5 using pre-children[0]=root if 5 had another child say 'x' then after x is returned from thr recursive call, u wud assign pre-children[1]=root where root is pointer to 5 here..but 8 and x have only one child which is 5 and indexes used for each are 0 and 1 instead of just 0..am i understanding it wrongly? On Wed, Dec 21, 2011 at 8:37 PM, atul anand atul.87fri...@gmail.com wrote: adding one more check :- this one is updated node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; break; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { if(root-children[i]!=NULL) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } } return root; } On Thu, Dec 22, 2011 at 9:35 AM, atul anand atul.87fri...@gmail.comwrote: adding break to first loop...just to avoid unnecessary iterations. if (root-children[i]!=NULL) { flag=1; break; } end for On Wed, Dec 21, 2011 at 10:59 PM, atul anand atul.87fri...@gmail.comwrote: @shashank: yeah here is the algo , please me know if you find any bug:- node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } return root; } On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.com wrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@Arun : yup ...rite... so i guess this will work..once pointer has been updated for parent node. there is no need of other point from children[i+1] to n. so adding one more loop at the end. for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[0]=root; } } for(i=1;in;i++) root-children[i] = NULL; On Thu, Dec 22, 2011 at 1:45 PM, Arun Vishwanathan aaron.nar...@gmail.comwrote: @atul: can you explain what this is doing? for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } when u do tree reversal I see that child points to parent( basically direction reversed). Now if 1 /|\ 234 //\ 5 6 7 /\ 89 in the last iteration along leftmost path , pointer to 8 is returned(pre) whose child is then assigned as 5 using pre-children[0]=root if 5 had another child say 'x' then after x is returned from thr recursive call, u wud assign pre-children[1]=root where root is pointer to 5 here..but 8 and x have only one child which is 5 and indexes used for each are 0 and 1 instead of just 0..am i understanding it wrongly? On Wed, Dec 21, 2011 at 8:37 PM, atul anand atul.87fri...@gmail.comwrote: adding one more check :- this one is updated node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; break; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { if(root-children[i]!=NULL) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } } return root; } On Thu, Dec 22, 2011 at 9:35 AM, atul anand atul.87fri...@gmail.comwrote: adding break to first loop...just to avoid unnecessary iterations. if (root-children[i]!=NULL) { flag=1; break; } end for On Wed, Dec 21, 2011 at 10:59 PM, atul anand atul.87fri...@gmail.comwrote: @shashank: yeah here is the algo , please me know if you find any bug:- node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } return root; } On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.com wrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
A better representation for a n-ary tree would be struct node{ int data; node* left; node* sibling; } Like in a binary tree the second ptr points to its right child . Here it points to its sibling.This one saves space and also We know in each level we have how many nodes @Shashank, I think we can reverse the n-ary tree ,but again my doubt is what will be leaf nodes then in that case , It seems it will be original root , so i was confused . anyway , I will concentrate on reversing the tree only for now based on ur definition. Regards Ankur On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.comwrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@Ankur : didnt understand , how you want to represent n-ary using this structure. struct node{ int data; node* left; node* sibling; } if root has 5 children then how will root point to its children using 2 pointers( left ,sibiling) On Wed, Dec 21, 2011 at 3:13 PM, Ankur Garg ankurga...@gmail.com wrote: A better representation for a n-ary tree would be struct node{ int data; node* left; node* sibling; } Like in a binary tree the second ptr points to its right child . Here it points to its sibling.This one saves space and also We know in each level we have how many nodes @Shashank, I think we can reverse the n-ary tree ,but again my doubt is what will be leaf nodes then in that case , It seems it will be original root , so i was confused . anyway , I will concentrate on reversing the tree only for now based on ur definition. Regards Ankur On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.comwrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@shashank: yeah here is the algo , please me know if you find any bug:- node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } return root; } On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.comwrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
i guess there is one more if i am not wrong; if(n==null) { n=n.children[++j]; return null; } here when n==NULLyou are doing n.children[++j].will give segmentation fault. On Wed, Dec 21, 2011 at 7:05 PM, WgpShashank shashank7andr...@gmail.comwrote: @all just a small bug found after discussing with one of the friend , i forgot to put the for loop , in 2nd if condition . Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/1cMtxb4Fy8wJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
adding one more check :- this one is updated node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; break; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { if(root-children[i]!=NULL) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } } return root; } On Thu, Dec 22, 2011 at 9:35 AM, atul anand atul.87fri...@gmail.com wrote: adding break to first loop...just to avoid unnecessary iterations. if (root-children[i]!=NULL) { flag=1; break; } end for On Wed, Dec 21, 2011 at 10:59 PM, atul anand atul.87fri...@gmail.comwrote: @shashank: yeah here is the algo , please me know if you find any bug:- node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } return root; } On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.comwrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
adding break to first loop...just to avoid unnecessary iterations. if (root-children[i]!=NULL) { flag=1; break; } end for On Wed, Dec 21, 2011 at 10:59 PM, atul anand atul.87fri...@gmail.comwrote: @shashank: yeah here is the algo , please me know if you find any bug:- node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } return root; } On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.comwrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
just a thought . to reverse the given tree is like finding inorder successor of the nodes. and every time we find a leaf node add it to the linked list. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank shashank7andr...@gmail.comwrote: here is my code ListNode list=new LinkeListNode(); public ListNode reverseTreeandReturnListContainingAllLeafNOdes(Node n) { int i=0; static int j=0; if(n==null) { n=n.children[++j]; return null; } if(n.children[i]==null) { list.add(n); return list; } list=reverseTreeandReturnListContainingAllLeafNOdes(n.children[i]); n.children[i]=n; return list; } may contains the bug ? any modification / suggestion will be appreciated Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2puK42n-1yYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
Hey Shashank Unfortunately I cudnt understand the problem What do u mean by reversing the tree here :(.. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank shashank7andr...@gmail.comwrote: here is my code ListNode list=new LinkeListNode(); public ListNode reverseTreeandReturnListContainingAllLeafNOdes(Node n) { int i=0; static int j=0; if(n==null) { n=n.children[++j]; return null; } if(n.children[i]==null) { list.add(n); return list; } list=reverseTreeandReturnListContainingAllLeafNOdes(n.children[i]); n.children[i]=n; return list; } may contains the bug ? any modification / suggestion will be appreciated Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2puK42n-1yYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@ankur : for the given tree above instead of parent pointing to its child , it would be child pointing to its parent after reversing i guess thats wat he is trying to say. On Tue, Dec 20, 2011 at 11:38 PM, Ankur Garg ankurga...@gmail.com wrote: Hey Shashank Unfortunately I cudnt understand the problem What do u mean by reversing the tree here :(.. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank shashank7andr...@gmail.comwrote: here is my code ListNode list=new LinkeListNode(); public ListNode reverseTreeandReturnListContainingAllLeafNOdes(Node n) { int i=0; static int j=0; if(n==null) { n=n.children[++j]; return null; } if(n.children[i]==null) { list.add(n); return list; } list=reverseTreeandReturnListContainingAllLeafNOdes(n.children[i]); n.children[i]=n; return list; } may contains the bug ? any modification / suggestion will be appreciated Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2puK42n-1yYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@Atul Even i thought so..but then the definition of leaf node is that its a node which doesnt have any children...then the answer is root of the original tree so I got confused here :( On Wed, Dec 21, 2011 at 12:20 AM, atul anand atul.87fri...@gmail.comwrote: @ankur : for the given tree above instead of parent pointing to its child , it would be child pointing to its parent after reversing i guess thats wat he is trying to say. On Tue, Dec 20, 2011 at 11:38 PM, Ankur Garg ankurga...@gmail.com wrote: Hey Shashank Unfortunately I cudnt understand the problem What do u mean by reversing the tree here :(.. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank shashank7andr...@gmail.com wrote: here is my code ListNode list=new LinkeListNode(); public ListNode reverseTreeandReturnListContainingAllLeafNOdes(Node n) { int i=0; static int j=0; if(n==null) { n=n.children[++j]; return null; } if(n.children[i]==null) { list.add(n); return list; } list=reverseTreeandReturnListContainingAllLeafNOdes(n.children[i]); n.children[i]=n; return list; } may contains the bug ? any modification / suggestion will be appreciated Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2puK42n-1yYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@rahul : i dont think so , i guess what u are telling will be like creating mirror image of the tree. On Wed, Dec 21, 2011 at 6:23 AM, rahul rahul...@gmail.com wrote: How do you represent the N-ary tree? If you represent child nodes as a list, reversing this child node list at each node will solve the problem right? I may be wrong. On Dec 20, 10:50 am, atul anand atul.87fri...@gmail.com wrote: @ankur : for the given tree above instead of parent pointing to its child , it would be child pointing to its parent after reversing i guess thats wat he is trying to say. On Tue, Dec 20, 2011 at 11:38 PM, Ankur Garg ankurga...@gmail.com wrote: Hey Shashank Unfortunately I cudnt understand the problem What do u mean by reversing the tree here :(.. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank shashank7andr...@gmail.comwrote: here is my code ListNode list=new LinkeListNode(); public ListNode reverseTreeandReturnListContainingAllLeafNOdes(Node n) { int i=0; static int j=0; if(n==null) { n=n.children[++j]; return null; } if(n.children[i]==null) { list.add(n); return list; } list=reverseTreeandReturnListContainingAllLeafNOdes(n.children[i]); n.children[i]=n; return list; } may contains the bug ? any modification / suggestion will be appreciated Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2puK42n-1yYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@Ankur , we need to reverse the pointer for each node so that points to their parents. thats what reversal a n-Ary tree means hope it help . have a look at my code , its just thought i approached using preorder traversal , but not getting correct answer , seems like missing something Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/ckr-RH9r4E4J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.