Cookies help us deliver our services. By using our services, you agree to our use of cookies. Click here to learn more

Interview Question

Software Development Engineer Intern Interview(Student Candidate) Redmond, WA

Print a binary tree level by level in zigzag order


Interview Answer

3 Answers


You should use two stacks: for the current level and for the next one.

Alexey on 7 Jan 2013

Use a queue.
1.Push root on queue.
2. Begin Loop Repeat while node is not equal to NULL:
            a. Pop
            b. Print value
            c. Push node's Right Child
            d. Push node's Left Child
3. End

Nofel on 27 Jan 2013

The answer given by me above is wrong because I was not clear about the zig zag ordering I applied it wrong !

Nofel on 27 Jan 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.