Re: [algogeeks] Re: Microsoft Interview Qn
This can be done like this 1. find out the height of the tree 2. make the number of arrays(node* pointers)=height of tree 3. traverse the tree from root as arr0[0]=root; arr1[0]=root-left; arr1[1]=root-right arr2[0]=arr1[0]-left arr2[1]=arr1[1]-right . . . and so on note:- if any arr[n]==NULL then make corresponding left and right entries NULL too now make the tree entries as :- arr[n]-right=arr[n+1] if arr[n] is last entry of tree make its right node NULL we are done :) On Sun, Jul 17, 2011 at 11:22 AM, naveen ms naveenms...@gmail.com wrote: in this recursive code...the right link node will point to its sibling to the right (if it has) or else it will be null. the left link of the node will point to its child(if it has) or else it will be null. regards, Naveen CSE R.V.C.E, Bangalore. -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- 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: Microsoft Interview Qn
This can be done using single array too... :) :) Do anybody wants the code? On Sun, Jul 17, 2011 at 3:04 PM, sagar pareek sagarpar...@gmail.com wrote: This can be done like this 1. find out the height of the tree 2. make the number of arrays(node* pointers)=height of tree 3. traverse the tree from root as arr0[0]=root; arr1[0]=root-left; arr1[1]=root-right arr2[0]=arr1[0]-left arr2[1]=arr1[1]-right . . . and so on note:- if any arr[n]==NULL then make corresponding left and right entries NULL too now make the tree entries as :- arr[n]-right=arr[n+1] if arr[n] is last entry of tree make its right node NULL we are done :) On Sun, Jul 17, 2011 at 11:22 AM, naveen ms naveenms...@gmail.com wrote: in this recursive code...the right link node will point to its sibling to the right (if it has) or else it will be null. the left link of the node will point to its child(if it has) or else it will be null. regards, Naveen CSE R.V.C.E, Bangalore. -- 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- 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.
[algogeeks] Re: Microsoft Interview Qn
plz give some example..sry but what do you mean by child sibling version?? On Jul 16, 3:46 pm, Reynald reynaldsus...@gmail.com wrote: Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- 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: Microsoft Interview Qn
im a bit confused with child-sibling term, this expects output for input: A /\ B C / \ / \ DE F G output: A / B C / / DE FG -- 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.
[algogeeks] Re: Microsoft Interview Qn
@Ashish: if i got ur algo correct, contrary to all the above examples, u r forming a linked list of level order traversal of the tree. m i right? On Jul 17, 8:49 pm, Ashish Goel ashg...@gmail.com wrote: 1. PUSH ROOT IN Q 2. PUSH DUMMY NODE IN Q, DEFINE PREVIOUS NODE AS NULL 3. WHILE Q IS NOT EMPTY 3A. POP CURRENT NODE 3B. IF CURRENT NODE IS NOT DUMMY 3B1. IF PREVIOUS, PREVIOUS-SIBLING = CURRENT. 3B2. PREVIOUS = CURRENT 3B3. PUSH CURRENT-LEFT, CURRENT-RIGHT TO Q (ONLY IF THE NODES ARE NOT NULL) 3C IF CURRENT NODE IS DUMMY 3C1 IF PREVIOUS, PREVIOUS-SIBLING = NULL; 3C2 PUSH DUMMY ON Q Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, Jul 16, 2011 at 4:16 PM, Reynald reynaldsus...@gmail.com wrote: Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- 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.- Hide quoted text - - Show quoted text - -- 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.
[algogeeks] Re: Microsoft Interview Qn
void convert(Node * root, Node* sibling) { if(root == NULL) return; convert(root-left, root-right); convert(root-right, NULL); root-right = sibling; } convert(root, NULL); -- DK http://twitter.com/divyekapoor http://www.divye.in -- 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/-/UTKqLB7fawgJ. 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: Microsoft Interview Qn
im a bit confused with child-sibling term, this expects output for A /\ B C / \ / \ DE F G 1 A / B C / / DE FG 2 A / B-- C / DEFG is output expected 1 or 2 surender On Sun, Jul 17, 2011 at 1:32 AM, DK divyekap...@gmail.com wrote: void convert(Node * root, Node* sibling) { if(root == NULL) return; convert(root-left, root-right); convert(root-right, NULL); root-right = sibling; } convert(root, NULL); -- DK http://twitter.com/divyekapoor http://www.divye.in -- 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/-/UTKqLB7fawgJ. 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: Microsoft Interview Qn
in this recursive code...the right link node will point to its sibling to the right (if it has) or else it will be null. the left link of the node will point to its child(if it has) or else it will be null. regards, Naveen CSE R.V.C.E, Bangalore. -- 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.