Depth First Search - Breadth First Search On A 2D-Grid allows people to traverse and search for a particular cell/vertex/node/number in a 2D-Grid.
Explore the docs Β»
Report Bug
Request Feature
Table of Contents
- Depth First Search - Breadth First Search On A 2D-Grid allows people to traverse and search a particular number in a 2D-Grid.
- Depth-First Search (DFS) and Breadth-First Search (BFS) are two techniques of traversing graphs and trees. DFS explores a graph or tree by diving as deeply as possible along a branch before backtracking, making it well-suited for tasks like finding paths and topological sorting. It is implemented using the stack data structure and recursion. Arrays/Lists can be used to implement the stack data structure.
- BFS systematically explores all neighbors of a node before moving to their neighbors, making it ideal for finding the shortest path in unweighted graphs and efficiently visiting nodes level by level. BFS employs a queue to maintain a first-in-first-out order, allowing them to serve different graph exploration needs.
- Given the 2D-Grid in the below Figure, start at the black 1 position and reach the goal at the red 15 position. Find the path to the goal using:
- Depth First Search (DFS)
- Breadth First Search (BFS)
- Usually we see Depth-First Search (DFS) and Breadth-First Search (BFS) on a Tree. However, they can also be used in a graph or grid which is what we do here.
To get a local copy of the Depth First Search - Breadth First Search On A 2D-Grid up and running locally follow these simple example steps:
NOTE: How to check if Python is installed and what is its version
python --versionNOTE: How to check if Git is installed and what is its version
git -v-
Please make sure you have pyenv installed and use any Python3 version:
- You can use pyenv to switch between different Python versions:
-
Please make sure you have git installed
-
Navigate to the directory where you want to clone/run/save the application
cd your_selected_directory -
Clone this repository
git clone https://github.com/GeorgiosIoannouCoder/dfs-bfs.git
-
Navigate to the dfs-bfs git repository
cd dfs-bfs -
Use any Python3 version in the cloned repository folder:
pyenv local 3.xx.xx -
Create virtual environment in the cloned repository folder
python -m venv .dfs-bfs-venv
-
Activate the virtual environment (Windows OR Mac/Linux):
- Windows
.\.dfs-bfs-venv\Scripts\activate
- Mac/Linux
source .dfs-bfs/bin/activate -
Install ipykernel:
pip install ipykernel
-
Install Jupyter Notebook:
pip install jupyter notebook
-
Add the kernel of the virtual environment in the Jupyter Notebook:
ipython kernel install --user --name=.dfs-bfs-venv- Run the Jupyter Notebook:
jupyter notebook-
Select the .dfs-bfs-venv kernel to run the Jupyter Notebook.
-
Run the two notebooks found in this repository.
- Define/Input a grid, starting cell, goal cell, and traversal directions, use Depth First Search (DFS) or Breadth First Search (BFS) to find the goal cell in the 2D-Grid.
- You can use the two notebooks above for both Depth First Search (DFS) and Breadth First Search (BFS)
- The two notebooks above were coded having in mind the problem statement mentioned in the introduction.
- You can find the first report for this project here where it shows step by step how Depth First Search (DFS) and Breadth First Search (BFS) work to find the goal cell.
- You can find the second report for this project here where it shows the time and space complexity of both Depth First Search (DFS) and Breadth First Search (BFS).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
MIT License
Copyright (c) 2023 Georgios Ioannou
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Georgios Ioannou - @LinkedIn
Georgios Ioannou - @georgiosioannoucoder - Please contact me via the form in my portfolio.
Project Link: https://github.com/GeorgiosIoannouCoder/dfs-bfs
