Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f156551

Browse files
Breadth First Search
1 parent a3bd9d1 commit f156551

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
Graph traversal means visiting every vertex and edge exactly once in a well-defined order.
3+
While using certain graph algorithms, you must ensure that each vertex of the graph is visited exactly once.
4+
The order in which the vertices are visited are important and may depend upon the algorithm or question that
5+
you are solving.
6+
7+
During a traversal, it is important that you track which vertices have been visited.
8+
The most common way of tracking vertices is to mark them.
9+
Breadth First Search (BFS)
10+
11+
There are many ways to traverse graphs. BFS is the most commonly used approach.
12+
BFS is a traversing algorithm where you should start traversing from a selected node (source or starting node)
13+
and traverse the graph layerwise thus exploring the neighbour nodes (nodes which are directly connected to source node).
14+
You must then move towards the next-level neighbour nodes.
15+
16+
As the name BFS suggests, you are required to traverse the graph breadthwise as follows:
17+
- First move horizontally and visit all the nodes of the current layer
18+
- Move to the next layer
19+
20+
Time Complexity: O(V + E)
21+
Space Complexity: O(V)
22+
V is number of vertices (nodes), E is number of edges
23+
'''

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /