Hi ,

We can do Breadth first search but without any additional Memory like Queue.
Since we connect the siblings we can traverse through siblings.
Going from Top to bottom, Each Internal node(non-leaf) must connect its
children. If that internal node has a right sibling then connect the right
most node of internal node with the left most child node of the sibling.
Continue until the sibling node is null. As you towards right remove the
links to its parent. Also save the left most node at each level to traverse
down to next level.



On Thu, May 13, 2010 at 6:57 PM, Jitendra Kushwaha <jitendra.th...@gmail.com
> wrote:

> This can be done with level order traversal of the tree
>
> Algorithm
>
> count = count2 = 0
> 1. Push the root in the queue.
> 2. keep count at each level for root count =1
> 3. while(queue not empty)
> 4.      push all childs of node at the top of queue in queue
> 5.      count2 += (number of childs of node at the top)
> 6.      print the top node of queue and dequeue it
> 7.      count -= 1
> 8.      if (count == 0)
> 9.            print newline
> 10.          count = count2
> 11.          count2 = 0
>
>
> any comments are welcomed...
>
> --
> Regards
> Jitendra Kushwaha
> Undergradute Student
> Computer Science & Eng.
> MNNIT, Allahabad
>
> --
> 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.
>

-- 
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