-
Notifications
You must be signed in to change notification settings - Fork 1
Update GraphBFSAdjList.java #2
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,16 @@ | ||
| # Breadth First Search Using Adjacent List | ||
|
|
||
| ## BFS Algorithm | ||
| The general process of exploring a graph using breadth-first search using adjacency list includes the following steps:- | ||
|
|
||
| -Take the input of adjacency list for the graph. | ||
| -Initialize a queue. | ||
| -Enqueue the root node (in other words, put the root node into the beginning of the queue. | ||
| -Dequeue the head (or first element) of the queue, then enqueue all of its neighboring nodes, starting from left to right. If a node has no neighboring nodes which need to be explored, simply dequeue the head and continue the process. (Note: If a neighbor which is already explored or in the queue appears, don’t enqueue it – simply skip it.) | ||
| -Keep repeating this process till the queue is empty. | ||
|
|
||
|
|
||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedList; | ||
| import java.util.Queue; | ||
|
|
@@ -59,4 +72,11 @@ public static void main(String[] args) { | |
| System.out.println("BFS:"); | ||
| g.bfs(2); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ## Time and Space Complexities | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once again you've done the same changes. You either have to add these as a comment or add a markdown file with the same things. Better to create a file GraphBFSAdjList.md and add the code over there and add your comments.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got that !!!
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Noob-Master-22 Where are the new changes? |
||
|
|
||
| The running time complexity of the BFS in Java is O(V+E) where V is the number of nodes in the graph, and E is the number of edges. | ||
|
|
||
| Since the algorithm requires a queue for storing the nodes that need to be traversed at any point in time, the space complexity is O(V). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Noob-Master-22 You're adding Markdown in a
.javafile. It has to be in a.mdfile. I guess you're doing this wrong. This will break the code.You need to create another markdown file. And add the code over there. And then add those comments.