bfs_and_dfs_implementation_v2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
bfs_and_dfs_implementation_v2 [2023/11/09 18:18] – [Depth First Search] fpalustre | bfs_and_dfs_implementation_v2 [2023/11/13 09:56] (current) – fpalustre | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== BFS & DFS Implementation | + | ====== BFS & DFS Implementation |
**Author:** Francis Palustre Email: < | **Author:** Francis Palustre Email: < | ||
\\ | \\ | ||
- | **Date:** Last modified on <11/09/23> | + | **Date:** Last modified on <11/13/23> |
\\ | \\ | ||
**Keywords: | **Keywords: | ||
Line 9: | Line 9: | ||
{{ : | {{ : | ||
\\ | \\ | ||
- | The photo above depicts | + | The photo above depicts the environment used for travel |
\\ | \\ | ||
===== Motivation and Audience ===== | ===== Motivation and Audience ===== | ||
- | This tutorial' | + | This tutorial' |
<fc blue> | <fc blue> | ||
Line 21: | Line 21: | ||
* Know how to navigate within the terminal in Linux | * Know how to navigate within the terminal in Linux | ||
\\ | \\ | ||
- | * This tutorial may also attract readers who are interesting | + | * This tutorial may also attract readers who are interested |
</fc> | </fc> | ||
\\ \\ | \\ \\ | ||
Line 179: | Line 179: | ||
} | } | ||
==== Breadth First Search==== | ==== Breadth First Search==== | ||
+ | {{ youtube> | ||
Algorithm for BFS | Algorithm for BFS | ||
Line 213: | Line 214: | ||
} | } | ||
} | } | ||
+ | //if no path, return empty vector | ||
return vector< | return vector< | ||
} | } | ||
Line 220: | Line 222: | ||
\\ | \\ | ||
There are two ways to traverse in DFS, an iterative approach and recursive approach. The following is a recursive approach because it is the most common. In the source code, there will be iterative as well. | There are two ways to traverse in DFS, an iterative approach and recursive approach. The following is a recursive approach because it is the most common. In the source code, there will be iterative as well. | ||
+ | |||
+ | |||
+ | vector< | ||
+ | // | ||
+ | | ||
+ | |||
+ | // | ||
+ | | ||
+ | |||
+ | //get adjacent nodes of starting node | ||
+ | | ||
+ | |||
+ | // | ||
+ | for ( vector< | ||
+ | const string& nextNode = *adjNodes; | ||
+ | |||
+ | //check if next node has been visited | ||
+ | if (!visited[nextNode]) { | ||
+ | // | ||
+ | vector< | ||
+ | | ||
+ | //if subPath not empty, path to desired node is found | ||
+ | if (!subPath.empty()) { | ||
+ | // | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | //if no path, return empty vector | ||
+ | return vector< | ||
+ | } | ||
+ | |||
==== Final Words ==== | ==== Final Words ==== | ||
Line 225: | Line 260: | ||
\\ | \\ | ||
\\ | \\ | ||
- | Speculating future work derived from this tutorial, includes | + | Speculating future work derived from this tutorial, includes |
\\ | \\ | ||
\\ | \\ |
bfs_and_dfs_implementation_v2.1699582686.txt.gz · Last modified: by fpalustre