I got this question in an interview with amazon.
I was asked to perform a depth first traversal of a tree, without using recursion or stack. I could use a parent pointer for each node, as a part of the structure, but nothing else other than that.(for ex, a “visited” variable” or anything).
Please suggest me an algorithm.
I got this question in an interview with amazon. I was asked to perform
Share
The parent pointer is actually all you need. The trick is to consume the tree as you traverse it.
Ugly pseudocode: