Reading notes for Code Fellows!
Recursion is the most common method of tree traversal and utilizes a call stack. There are three methods for depth first traversal. They are:
root
-> left
-> right
current
nodecurrent
valueleft
child of the current
nodecurrent
to stack then make child the current
node and go back to 2right
child of the current
nodecurrent
to stack then make child the current
node and go back to 2current
node, pop the node off of the stack and go back to 2Output from example tree:
A
-> B
-> D
-> E
-> C
-> F
left
-> root
-> right
current
nodeleft
child of the current
nodecurrent
to stack and make child the current
node and go back to 2current
valueright
child of the current
nodecurrent
to stack and make child the current
node and go back to 2current
node, pop the node off of the stack and go back to 2Output from example tree:
D
-> B
-> E
-> A
-> F
-> C
left
-> right
-> root
current
nodeleft
child of the current
nodecurrent
to stack then make child the current
node and go back to 2right
child of the current
nodecurrent
to stack then make child the current
node and go back to 2current
valuecurrent
node, pop the node off of the stack and go back to 2Output from example tree:
D
-> E
-> B
-> F
-> C
-> A