How abt representing the tree as a graph. If you represent it in
adjacency mattix or as a map of edges e.g. Edge{from}{to}=edge weight,
which could be a constant in this case. all you need to is to reverse
the pairs.

Order of complexity is o(e) and you can reach to leaf nodes and push
them in a list

On Dec 21, 1:43 am, Ankur Garg <[email protected]> wrote:
> A better representation for a n-ary tree would be
>
> struct node{
>     int data;
>    node* left;
>    node* sibling;
>
> }
>
> Like in a binary tree the second ptr points to its right child . Here it
> points to its sibling.This one saves space and also We know in each level
> we have how many nodes
> @Shashank,
> I think we can reverse the n-ary tree ,but again my doubt is what will be
> leaf nodes then in that case , It seems it will be original root , so i was
> confused . anyway , I will concentrate on reversing the tree only for now
> based on ur definition.
>
> Regards
> Ankur
>
> On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank 
> <[email protected]>wrote:
>
>
>
>
>
>
>
> > @atul,, yeah , but can you write some proper psuedo code/ Algorithm then
> > we can discus more about test cases.
>
> > Thanks
> > Shashank
>
> > --
> > 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/-/VPZpHM8D_WcJ.
>
> > 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.

Reply via email to