Zig Zag Tree Traversal in Java - FitCoding
Zig Zag Tree Traversal in Java Write a method to find the zig zag tree traversal in a tree. I got asked this question once in an interview. Now I found a few solutions to this problem over the internet, but none was really explaining how to get to the solution, instead just provide one. I will try to explain step by step how to come up with a solution, so you get in the habit of applying this thought process to other problems as well. First as usual, let us try to clarify any assumptions: Are we talking about any tree or a binary tree. Let us assume for this question that we are talking about a binary tree. What is a zig zag tree traversal? Well as the name implies, is a traversal of the tree going zig zag each level, from top to bottom. Do we go left-first or right-first? This is actually a great question. A zig zag tree traversal could go both ways, but for simplicity we will assume we want the right zig zag tree traversal.Read full article from Zig Zag Tree Traversal in Java - FitCoding
No comments:
Post a Comment