Professional Documents
Culture Documents
Report On The Applications of DFS and BFS
Report On The Applications of DFS and BFS
This report contains the information about the applications of DFS and BFS.
Depth-first search (DFS) is an algorithm (or technique) for traversing a graph.
The algorithm starts at the root (top) node of a tree and proceeds as far down a
particular branch (path) as it can, then backtracks until it discovers an unexplored
path, which it then explores. This is repeated by the algorithm until the entire
graph has been discovered. Graphs may be used to solve a lot of issues in
computer science. Graph challenges include, for example, evaluating networks,
mapping routes, scheduling, and identifying spanning trees.
Graph-search techniques like depth-first search are beneficial for analyzing these
difficulties. Depth-first search is a common way that many people naturally
approach solving problems like mazes. First, we take a way through the labyrinth
and follow it until we reach a dead end or the maze's end. If a certain path does
not work, we retreat and attempt an alternate way from a previous junction. DFS
is a great way to deal with mazes and other puzzles that have only one solution.
DFS may be implemented in three distinct ways: pre-order, in-order, and post-
order.
Pre-order DFS works by starting at the current node and going left until you reach
a leaf, stopping at each node along the way. When the children on the left of a
node are no longer visited, the children on the right are visited. The most used
DFS algorithm is this one.
An in-order method finds the leftmost node in the tree, visits that node, and then
visits the parent of that node instead of visiting each node as it progresses down
the tree. It then moves on to the kid on the right and searches for the tree's next
leftmost node to visit.
A post-order technique involves visiting the tree's leftmost leaf, then traveling up
to the parent and down the branch's second leftmost leaf, and so on until the
parent is the final node visited inside a branch. In the event of a goal at the end of
a tree, this sort of algorithm favors leaf processing above root processing.
A graph has a cycle if and only if a back edge is seen during DFS. As a result, we
can run DFS on the graph and look for back edges.
2) Path finding
We can use the DFS technique to find a route between two vertices, u and z.
3) Topological Sorting
When we initially find a new vertex, we may supplement either BFS or DFS by
coloring it opposite its parent`s and checking that each other edge does not
connect two vertices of the same color.
Breadth-first search begins by looking for a start node, then its surrounding
nodes, and finally all nodes that may be reached by a path from the start node
that has two edges, three edges, and so on.
In BFS, there are three sorts of vertices: tree vertices, which have been visited;
fringe vertices, which are next to tree vertices but have not yet been visited; and
unknown vertices, which have not yet been encountered.
In an unweighted graph, the shortest path is the one with the fewest edges. With
Breadth First, we always use the minimum number of edges to reach a vertex
from a given source. Furthermore, in the case of unweighted graphs, every
spanning tree is Minimum Spanning Tree, and we can identify a spanning tree
using either Depth or Breadth first traversal.
In social networks, we may use Breadth First Search to identify people within a
particular distance 'k' of a person up to 'k' levels.
The Breadth First Search method is used to locate all nearby sites.
6) Broadcasting in network
A broadcasted packet in a network uses Breadth First Search to reach all nodes.
7) In garbage collection
I have discovered that BFS and DFS have a lot of applications in real life and it is
very helpful in technology.
On the whole, it would be fair to conclude that Breadth-first search is better than
DFS because BFS maintains a priority queue for the whole frontier, whereas DFS
just retains a few pointers at each level.
When it is known that an answer will most likely be discovered deep inside a tree,
DFS is a better choice than BFS. BFS is useful when the depth of the tree might
change or when a single solution is required, such as the shortest path in a tree.
DFS is a superior alternative if the full tree must be visited.