caesar0301/pyTree — pull request #11 by ilya-spy (2013-08-11 09:36:14+00:00)
Title: - Added ZIGZAG support

Hi!

This is to support walking tree in ZIGZAG mode. I ahve added Tree.ZIGZAG constant and implementation to expand_tree() method with mode set to Tree.ZIGZAG.

The algorithm walks tree level-by-level (similar to width-first), but starts traversing each level from the opposite site compared to previous.

This is frequently asked on interviews in Google and Microsoft (this helps to better align hash/keys search in some specific cases). Algorithm uses 2 lists as stacks (current level travesring procedure pushes elements of next level into another stack) - i didn't able to figure out, how to made in using only one stack/queue