Skip to content

Instantly share code, notes, and snippets.

View geeksambhu's full-sized avatar
🎯
Focusing

Shiva Gaire geeksambhu

🎯
Focusing
View GitHub Profile
@geeksambhu
geeksambhu / tree_iterators.py
Created June 6, 2019 16:27 — forked from alexbowe/tree_iterators.py
Method to simplify many programming interview tree questions.
'''
Interview hack: Memorize preorder/inorder/postorder tree ITERATORS (no recursion) and their reverses.
It simplifies a disproportionate number of questions to simple for loops (see below).
I consider the implementations below the simplest way to memorize the iterative tree traversal algorithms,
because they are so similar to each other, and to their respective recursive versions.
Notes:
- We only visit a node after we have expanded its children (i.e. added them to the stack) in the desired order.
- `x is curr` does the expanded flagging for us, because we always expand the current node.
@geeksambhu
geeksambhu / about.md
Created December 27, 2016 18:33 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer