From fc350f8cee60bab509f05c0060296063fb8bb34a Mon Sep 17 00:00:00 2001 From: Ash <121093841+Ashirz@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:18:56 +0000 Subject: [PATCH 1/3] Update BreathFirstSearch.md Fixed the typos for BFS. Also corrected the spelling 'Breadth' instead of 'Breath' --- .../Breath First Search/BreathFirstSearch.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Algorithms/Breath First Search/BreathFirstSearch.md b/src/Algorithms/Breath First Search/BreathFirstSearch.md index 78f6f22..6d7e4ee 100644 --- a/src/Algorithms/Breath First Search/BreathFirstSearch.md +++ b/src/Algorithms/Breath First Search/BreathFirstSearch.md @@ -1,4 +1,4 @@ -# Overview of the Depth First Search (DFS) Code in Java πŸ’» +# Overview of the Breadth First Search (BFS) Code in Java πŸ’» ## What's Happening in the Code? ❓ The provided Java code implements Breath First Search (BFS), a fundamental graph traversal algorithm. Let's walk through the details! @@ -11,10 +11,10 @@ private List> adjList; ``` ### 2. **Constructing the Graph** βš™οΈ -The `BreathFirstSearch` constructor initializes the adjacency list with `numVertices` empty lists: +The `BreadthFirstSearch` constructor initializes the adjacency list with `numVertices` empty lists: ```java -public BreathFirstSearch(int numVertices){ +public BreadthFirstSearch(int numVertices){ adjList = new ArrayList<>(); for (int i = 0; i < numVertices; i++){ adjList.add(new ArrayList<>()); @@ -108,11 +108,11 @@ private void bfsRecursiveUtil(Queue queue, boolean[] visited){ - **Recur**: For each unvisited neighbor, `bfsUtil` is called recursively. ### 6. **Main Method** πŸ’ͺ -Finally, the `main` method demonstrates the DBFS by building a sample graph and starting the traversal from vertex `0`: +Finally, the `main` method demonstrates the BFS by building a sample graph and starting the traversal from vertex `0`: ```java public static void main(String[] args) { - BreathFirstSearch graph = new BreathFirstSearch(6); + BreadthFirstSearch graph = new BreadthFirstSearch(6); //Adding edges to the graph graph.addEdge(0, 1); @@ -135,16 +135,16 @@ public static void main(String[] args) { ### Example Output: βœ… If you run the code, you might see an output like: ``` -Depth First Search starting from vertex 0: +Breadth First Search starting from vertex 0: 0 1 3 4 ``` This output shows the order in which the vertices are visited during the BFS traversal. ## Fun Fact: 🧐 -DFS is great for finding the shortest path in unweighted graphs, which is very useful for GPS Navigation systems. +BFS is great for finding the shortest path in unweighted graphs, which is very useful for GPS Navigation systems. And that’s how BFS works in Java! ### Created by -David Bernal based on the job done by Nkeiruka Whenu \ No newline at end of file +David Bernal based on the job done by Nkeiruka Whenu From 54b8ac097f11f6675bb7a92757c344f3e5b5b34a Mon Sep 17 00:00:00 2001 From: Ash <121093841+Ashirz@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:24:11 +0000 Subject: [PATCH 2/3] Update and rename BreathFirstSearch.java to BreadthFirstSearch.java Replaced 'Breath' to 'Breadth' --- .../{BreathFirstSearch.java => BreadthFirstSearch.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/Algorithms/Breath First Search/{BreathFirstSearch.java => BreadthFirstSearch.java} (95%) diff --git a/src/Algorithms/Breath First Search/BreathFirstSearch.java b/src/Algorithms/Breath First Search/BreadthFirstSearch.java similarity index 95% rename from src/Algorithms/Breath First Search/BreathFirstSearch.java rename to src/Algorithms/Breath First Search/BreadthFirstSearch.java index 7dc58cd..3bfed5d 100644 --- a/src/Algorithms/Breath First Search/BreathFirstSearch.java +++ b/src/Algorithms/Breath First Search/BreadthFirstSearch.java @@ -6,7 +6,7 @@ public class BreathFirstSearch { private List> adjList; //BFS class constructor to the adjacency list - public BreathFirstSearch(int numVertices){ + public BreadthFirstSearch(int numVertices){ adjList = new ArrayList<>(); for (int i = 0; i < numVertices; i++){ adjList.add(new ArrayList<>()); @@ -78,7 +78,7 @@ private void bfsRecursiveUtil(Queue queue, boolean[] visited){ //Main method to demonstrate BFS public static void main(String[] args) { - BreathFirstSearch graph = new BreathFirstSearch(6); + BreadthFirstSearch graph = new BreadthFirstSearch(6); //Adding edges to the graph graph.addEdge(0, 1); From 11fe7fea69e05e2f4537f0a6f2cc6bdb84c5b0b9 Mon Sep 17 00:00:00 2001 From: Ash <121093841+Ashirz@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:25:55 +0000 Subject: [PATCH 3/3] Rename BreathFirstSearch.md to BreadthFirstSearch.md --- .../{BreathFirstSearch.md => BreadthFirstSearch.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Algorithms/Breath First Search/{BreathFirstSearch.md => BreadthFirstSearch.md} (100%) diff --git a/src/Algorithms/Breath First Search/BreathFirstSearch.md b/src/Algorithms/Breath First Search/BreadthFirstSearch.md similarity index 100% rename from src/Algorithms/Breath First Search/BreathFirstSearch.md rename to src/Algorithms/Breath First Search/BreadthFirstSearch.md