top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Given a binary tree print it in inward spiral order i.e first print level 1, then level n, then 2, then n-1 and so on?

+3 votes
380 views

Given a binary tree print it in inward spiral order i.e first print level 1, then level n, then level 2, then n-1 and so on.

For Ex -

         1 
   2           3 
 4    5       6     7 
8 9  10 11  12 13  14 15 

Print- 1 15 14 13 12 11 10 9 8 2 3 7 6 5 4

posted Dec 10, 2015 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+6 votes

Given binary tree is:

        1
     /     \
    2        3
  /  \        \
 4   5         6
             /   \
            7     8

The output should be 1, 2, 3, 4, 5, 6, 7, 8

+1 vote

Suppose you are given a tree and asked to find out the first node at nth level. How can it be done? C code would be helpful?

+2 votes

consider the tree:

              1
            /   \
           2     3
          / \   / \
         4   5 6   7

spiral order traversal for the given tree is:1 2 3 7 6 5 4 or 1 3 2 4 5 6 7

+4 votes

Given binary tree is:

            1
         /     \
        2        3
      /  \        \
     4   5         6
                 /   \
                7     8

The output will be 7,8,4,5,6,2,3,1

...