Here is the algo :
while(read string in reverse)
{
if(str = L)
create node and push to stack
continue
if(str = N)
pop 2 nodes from stack and asign them as children of N and push N
on stack //Here we can get
//multiple trees
}
pop root from stack
On Thu, Feb 24, 2011 at 12:59 AM, Aviral Gupta <[email protected]> wrote:
> with the given constraints there is only one possible tree ....
>
> Regards
> Aviral
> http://coders-stop.blogspot.com
>
> On Feb 23, 5:47 pm, "[email protected]"
> <[email protected]> wrote:
> > hii vinay,
> >
> > the prob is we can get many such trees given a preorder traversal with
> the
> > condition that each node has zero or two children. Please correct me if I
> am
> > wrong.
> >
> > Thanks,
> > Krishna.
> >
> > On Wed, Feb 23, 2011 at 6:00 PM, [email protected] <
> >
> > [email protected]> wrote:
> > > thanks vinay :-)
> >
> > > On Wed, Feb 23, 2011 at 5:39 PM, vinay reddy <[email protected]>
> wrote:
> >
> > >> U need to construct a binary tree given only PreOrder traversal with
> the
> > >> condition that each node has zero or two children.
> >
> > >> On Wed, Feb 23, 2011 at 10:52 AM, [email protected] <
> > >> [email protected]> wrote:
> >
> > >>> hii vinay,
> >
> > >>> can u elaborate the third question
> >
> > >>> thanks,
> > >>> Krishna
> >
> > >>> On Wed, Feb 23, 2011 at 9:34 AM, vinay reddy <[email protected]
> >wrote:
> >
> > >>>> Hi Anurag,
> >
> > >>>> I have taken that online test there were 3 questions ...
> > >>>> 1. given a linked list check if it is a palindrome.
> > >>>> 2.given two sorted arrays a[m] b[2*m], each contains m elements
> only.
> > >>>> You need to merge those two arrays into second array b[2*m]
> > >>>> 3. construct a Binary tree from a given String, where every node has
> > >>>> zero or two children.
> > >>>> e.g String = "NNNLLL" , N represents internal Node , L represents
> leaf
> > >>>> Node.
> >
> > >>>> The alloted time was 1hr. and asked to write the function only ...
> no
> > >>>> main function and all.
> > >>>> hope this helps
> >
> > >>>> Thanks
> > >>>> vinay
> >
> > >>>> On Wed, Feb 16, 2011 at 3:45 PM, Anurag Bhatia <[email protected]
> >wrote:
> >
> > >>>>> Has anyone give any first round online test for Amazon? If yes, can
> > >>>>> you please share details?
> >
> > >>>>> --Anurag
> >
> > >>>>> --
> > >>>>> 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.
> >
> > >> --
> > >> 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.
>
>
--
Regards
Pranjal
--
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.