Microsoft

  www.microsoft.com
Work in HR? Unlock Free Profile

Microsoft Software Development Engineer Intern Interview Question (student candidate)

I interviewed in Redmond, WA and was asked:
"Print a binary tree level by level in zigzag order"
Add Tags [?]
Answer

Part of a Software Development Engineer Intern Interview Review - one of 3,366 Microsoft Interview Reviews

Answers & Comments

1
of 1
vote
You should use two stacks: for the current level and for the next one.
- Alexey on Jan 7, 2013
0
of 3
votes
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 Jan 27, 2013
1
of 1
vote
The answer given by me above is wrong because I was not clear about the zig zag ordering I applied it wrong !
- Nofel on Jan 27, 2013

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.