driver(Tree *root)
{
   node *array = malloc(sizeof(node *) *H ); /* take the height node
pointer array. this will act as source pointer of each list */
   makeList(root, 0, array)
}

makeList(Tree *root, int level, node *array)
{
   if(! root) return ;

  /*do a Depth traversal and store the list pointer*/
  append(array[level], root);

  /*Traverse the left and right subtrees and store them in list*/
  makeList(root->left, level+1, array);
  makeList(root->right, level+1, array);
}

time complexity is O(n) space complexity O(log n)
( assuming append has O(1) complexity)


On Aug 1, 2:26 am, Nikhil Jindal <fundoon...@yahoo.co.in> wrote:
> @Ram Kumar: Yes. Simple and affective.
>
> Just at each node:
>
> node->left->side=node->right
> node->right->side=node->side->left
>
> i.e at each node you are setting the side of each of your child. Go on and
> just do it for all nodes. Done.
>
> On Sat, Jul 31, 2010 at 9:39 AM, Ram Kumar <harrypotter....@gmail.com>wrote:
>
>
>
>
>
> > DONT DO A BFS!! NOT WORTH IT! CALL THE NEW POINTER AS 'SIDE' POINTER.
>
> > for every root connect its left and right, for every root connect
> > root->right and root->SIDE->left
>
> > that ll do
>
> > --
> > 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.
>
> Please access the attached hyperlink for an important electronic 
> communications 
> disclaimer:http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php- 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.

Reply via email to