Skip to content

Commit 1f0b727

Browse files
committed
modifying BFS image file.
1 parent 9f04e66 commit 1f0b727

File tree

2 files changed

+1
-1
lines changed

2 files changed

+1
-1
lines changed

chapters/fundamental_algorithms/tree_traversal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void DFS_stack(const node& n){
129129

130130
All this said, there are a few details about DFS that might not be idea, depending on the situation. For example, if we use DFS on an incredibly long tree, we will spend a lot of time going further and further down a single branch without searching the rest of the data structure. In addition, it is not the natural way humans would order a tree if asked to number all the nodes from top to bottom. I would argue a more natural traversal order would look something like this:
131131

132-
![BFS ordering](full_tree_BFS.png)
132+
![BFS ordering](BFS_simple.png)
133133

134134
And this is exactly what Breadth-First Search (BFS) does! On top of that, it can be implemented in the same way as the `DFS_stack(...)` function above, simply by swapping the `stack` for a `queue`, which is similar to a stack, exept that it only allows you to interact with the very first element instead of the last. In code, this looks something like:
135135

0 commit comments

Comments
 (0)