2. First find the given node by traversing tree (BFS) At every level maintain the list of parents of the current level being traversed. Whereever this node is found, then traverse and print both children of each parent in the list.
3. Find the paths to each node from root. This can be done by DFS. Once the 2 paths are found then they act like Singly linked list each (from root to given node). Now this problem becomes finding LCA (least common ancestor) of these tree nodes. Check to find latest common parent by comparing the nodes at each level. Wherever comparison breaks, stop. On Sun, Apr 10, 2011 at 2:54 AM, Anand <[email protected]> wrote: > binary tree > > > On Fri, Apr 8, 2011 at 11:54 PM, ArPiT BhAtNaGaR < > [email protected]> wrote: > >> U sure those r binary tree's & not BST >> >> On Sat, Apr 9, 2011 at 10:26 AM, Anand <[email protected]> wrote: >> >>> 1, You have 52 cards. How will you make your you distribute cards >>> randomly. >>> >>> 2. You have given a binary tree. Given any node, print the all the nodes >>> at the same level. >>> >>> 3. You have given a binary tree and two given nodes. Find the distance >>> between two nodes. >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> Arpit Bhatnagar >> (MNIT JAIPUR) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
