I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 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. |
- Related Setup: https://gist.github.com/hofmannsven/6814278
- Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
- Interactive Beginners Tutorial: http://try.github.io/
- Git Cheatsheet by GitHub: https://services.github.com/on-demand/downloads/github-git-cheat-sheet/
Press minus + shift + s and return to chop/fold long lines!