Algorithms Visually Explained The Breadth First Search algorithm is like the Depth First Search algorithm with the exception that it uses a queue rather than a stack. BFS is technically the opposite of DFS since the BFS algorithm explores the deepest nodes first before backtracking to explore the shallower nodes. An element can be enqueued or dequeued. The queue works on a first-in-first-out principle (FIFO), which means that the element that was enqueued first will be dequeued first. BFS works like this: Select the first node Explore all unvisited nodes and enqueue them Once all unvisited, adjacent nodes have been