Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos in Breadth First Search #82

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class BreathFirstSearch {
private List<List<Integer>> 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<>());
Expand Down Expand Up @@ -78,7 +78,7 @@ private void bfsRecursiveUtil(Queue<Integer> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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!
Expand All @@ -11,10 +11,10 @@ private List<List<Integer>> 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<>());
Expand Down Expand Up @@ -108,11 +108,11 @@ private void bfsRecursiveUtil(Queue<Integer> 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);
Expand All @@ -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
David Bernal based on the job done by Nkeiruka Whenu
Loading