You are on page 1of 7

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.

Depth-first search's basic technique is to go deeper into the graph whenever


possible. Edges that emerge from the most recently found vertex “s” are explored
using depth-first search. Only edges that go to vertices that haven't been
explored. The search backtracks until it finds an undiscovered neighbor after all of
vertex “s” edges have been investigated. This technique is repeated until all of the
vertices accessible from the initial source vertex have been found. If any vertices
have yet to be reached, depth-first search chooses one of them as a new source
and restarts the search from there. The method repeats this procedure until every
vertex has been identified. Because this method avoids repeating vertices, each
vertex is only investigated once. To keep track of vertices, DFS employs a stack
data structure.

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.

Topological sorting, scheduling issues, cycle detection in graphs, and solving


puzzles with just one solution, such as a labyrinth or a sudoku puzzle, all employ
depth-first search.

Other uses require network analysis, such as determining if a graph is bipartite.

Here are some applications of Depth-First-Search


1) Detecting cycle in a graph

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

Topological Sorting is mostly used for scheduling jobs based on work


dependencies. This type of application appears in computer science in
instruction scheduling.

4) Testing if a graph is bipartite

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.

5) Finding strongly connected components of a graph

A directed graph is said to be strongly connected if every vertex in the graph


has a route to every other vertex.
We have earlier discussed DFS. And now, we will continue discuss about the
applications of BFS

Breadth-first search (BFS) is a graph search technique used to tackle a variety of


issues, including finding the shortest path in a network and playing puzzle games
Many computer science issues may be expressed as graphs. Analyzing networks,
mapping routes, and scheduling are all examples of graph issues. Graph search
techniques, such as breadth-first search, can be used to analyze and solve graph
issues.

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.

To search a linked component of a network methodically, start with one vertex on


the fringe, all others unseen, and repeat the following step until all vertices have
been visited. The algorithm used to determine which vertex should be transferred
from the fringe to the tree varies amongst graph traversal methods. Choose the
most recently encountered vertex from the fringe for breadth-first search.

The breadth-first search method may be used to solve games in which a


succession of options results in either a winning or a losing state. BFS can, for
example, assist a player in determining a winning sequence of moves for solving a
Rubik's cube.
BFS is also utilized in the well-known Dijkstra's method, which computes the
shortest path in a graph, and the Ford-Fulkerson algorithm, which computes the
maximum flow in a flow network.

Here are some applications of Breadth-First-Search

1) Shortest path and minimum spanning tree for unweighted graph

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.

2) Peer to peer network

Breadth-First-Search is used to find all adjacent nodes

3) Crawlers in search engines

Crawlers create indexes by going Breadth-First-Search. The goal is to start at the


original page and follow all links from there, and then repeat the process.
However the advantage of Breadth-First-Search is that the depth or layers of the
created tree can be limited.

4) Social network websites

In social networks, we may use Breadth First Search to identify people within a
particular distance 'k' of a person up to 'k' levels.

5) GPS navigation systems

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

Breadth First Search is used in copying garbage collection using Cheney’s


algorithm.

8) Cycle detection in undirected graph


9) Using BFS for Ford-Fulkerson algorithm

To determine the maximum flow in the Ford-Fulkerson method, we can utilize


Breadth-First-Search. It is preferable to use Breadth-First-Search since it
decreases worst-case time complexity to O.

10) To test if a graph a Bipartite


11) Path finding
12) Finding all nodes within one connected component

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.

You might also like