The purpose of the graph traversal algorithms are two-fold.
This uses a queue to store child nodes. They are processes in FIFO order.
Visit a node, putting it's children (if it has any) in the queue.
Pop the front of the queue and process that node. Continue until the queue is empty.
Keep a side set to check for multiple visitation of the same node (cycle detection).
This uses a stack to store child nodes. They are processes in LIFO order.
Visit a node, putting it's children (if it has any) in the stack.
Pop the top of the queue and process that node. Continue until the stack is empty.
Keep a side set to check for multiple visitation of the same node (cycle detection).