you can use hashtable , hash at calculated index, no need of saving empty
spaces.

On Tue, Feb 7, 2012 at 4:38 PM, DT <[email protected]> wrote:

> Thanks for the reply. But is this solution the most efficient one or
> do we have better space complexity algos available? The code below
> will introduce array indexes with empty values whenever the left/right
> child is null.
>
> On Feb 7, 2:06 pm, atul anand <[email protected]> wrote:
> > algo will be something like this:-
> >
> > i=0;
> > arr[i]=root;
> > enqueue(root);
> >
> >  while queue is not empty
> >        temp=dequeue();
> >      i =search for element temp in array temp and return it index
> >      if(temp->left!=NULL)
> >      {
> >           arr[2*i+1]=temp->left;
> >           enqueue(temp->left);
> >      }
> >      if(temp->right!=NULL)
> >      {
> >
> >           arr[2*i+2]=temp->right;
> >           enqueue(temp->right);
> >     }
> >
> > }
> >
> > On Tue, Feb 7, 2012 at 2:18 PM, WgpShashank <[email protected]
> >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > @DT Use BFS (Queue) , try it.
> >
> > > --
> > > *Thanks
> > > Shashank Mani Narayan
> > > Computer Science & Engineering
> > > Birla Institute of Technology,Mesra
> > > ** Founder Cracking The Code Lab  "http://shashank7s.blogspot.com/"*
> >
> > >  --
> > > 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/-/NHU-lOy0_e8J.
> >
> > > 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.

Reply via email to