Yeah use BFS, push the nodes on a stack and make them point to each other. How they point depends on the question, which needs clarification. Should they ALL be connected to each other as in A to B and A to C and B to C or just A to B and B to C. Either way, the above approach should work fine.
-Minotauraus > > > On Thu, Jul 29, 2010 at 11:35 PM, ashish agarwal < > > ashish.cooldude...@gmail.com> wrote: > > >> please explain q ..i didnt understand > > >> On Thu, Jul 29, 2010 at 11:01 AM, irfan <irfannase...@gmail.com> wrote: > > >>> I attended Amazon placement test today . There was a question where i > >>> got confused.It is as follows. > > >>> Give an algorithm to connect all nodes in one level of a binary tree . > > >>> 5 > >>> 5 > >>> / > >>> \ / \ > >>> 8 2 --------> 8 ---- > >>> > 2 > >>> / \ / / > >>> \ / > >>> 1 2 6 1 ---> 2 -->6 > > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "Algorithm Geeks" group. > >>> To post to this group, send email to algoge...@googlegroups.com. > >>> To unsubscribe from this group, send email to > >>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@googlegroups.com. > >> To unsubscribe from this group, send email to > >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > >> . > >> For more options, visit this group at > >>http://groups.google.com/group/algogeeks?hl=en. > > > Sorry for that. I attached a jpg file showing what shud the algo do . > > Question is that, we are given a tree. algo shud connect all the nodes > > which are in same level. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algoge...@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@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.