Highbridge Capital Interview Question
Java DevelopersCountry: United States
Interview Type: In-Person
Algo :
1) Push root into Stack
2) Now iterate steps 3,4,5 with condition - while(stack is not empty)
3) Pop a node, print it
4) if node->right is not NULL, push it
5) if node->left is not NULL, push it
Full working code here :
awesomecoder.blogspot.com/2012/08/preorder-traversal-of-bst-iteratively.html
You can understand the concept by watching this video
Iterative Preorder tree traversal
youtube.com/watch?v=uPTCbdHSFg4
Iterative postorder tree traversal
youtube.com/watch?v=hv-mJUs5mvU
Iterative inorder tree traversal
youtube.com/watch?v=50v1sJkjxoc
- Vir Pratap Uttam May 04, 2015