@ Ashish: make a balanced binary tree of depth >3 and try the approach, u need to save the pointers somewhere if they are in different subtrees and at same level. Stack will be most appropriate one to use for this purpose.
On Aug 2, 7:34 pm, Ashish Goel <ashg...@gmail.com> wrote: > why stack? that is DFS > > it would need a queue and a null node inserted as a level is traversed > > something similar to find max width in a tree > > the only differnece is as you move along a level, make the connections > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > > > On Fri, Jul 30, 2010 at 3:38 AM, Minotauraus <anike...@gmail.com> wrote: > > 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> > > <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> > > <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> > > <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<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.