Sarah Mae E.
Padaboc
BSCS 3A
Intelligent Systems
Breadth First Search and Depth First Search Algorithms
Breadth First Search Algorithm is an algorithm efficiently visits and marks all the key
nodes in a graph in an accurate breadthwise fashion. This algorithm selects a single node
(initial or source point) in a graph and then visits all the nodes adjacent to the selected
node.
Once the algorithm visits and marks the starting node, then it moves towards the
nearest unvisited nodes and analyses them. Once visited, all nodes are marked. These
iterations continue until all the nodes of the graph have been successfully visited and
marked.
Breadth-First Search Algorithm Pseudocode
Here’s the pseudocode to implement the Breadth-First Search Algorithm:
1 Input: s as the source node
2
3 BFS (G, s)
4 let Q be queue.
5 Q.enqueue( s )
6
7 mark s as visited
8 while ( Q is not empty)
9 v = Q.dequeue( )
10
11for all neighbors w of v in Graph G
12if w is not visited
13Q.enqueue( w )
14mark w as visited
https://www.edureka.co/blog/breadth-first-search-algorithm/
One Example of Breadth First Search Algorithm:
GPS Navigation Systems. Breadth First Search is used to find all neighboring locations.
Navigation systems as the Google Maps, which can give directions to reach from one
place to another uses BFS. They take your location to be the source node and your
destination as the destination node on the graph. (A city can be represented as a graph
by taking landmarks as nodes and the roads as the edges that connect the nodes in the
graph.) BFS is applied and the shortest route is generated which is used to give directions
or real time navigation.
Sarah Mae E. Padaboc
BSCS 3A
Intelligent Systems
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data
structures. The algorithm starts at the root node (selecting some arbitrary node as the
root node in the case of a graph) and explores as far as possible along each branch
before backtracking.
Depth-first search (DFS) is an algorithm pseudocode
DFS(G,v) ( v is the vertex where the search starts )
Stack S := {}; ( start with an empty stack )
for each vertex u, set visited[u] := false;
push S, v;
while (S is not empty) do
u := pop S;
if (not visited[u]) then
visited[u] := true;
for each unvisited neighbour w of u
push S, w;
end if
end while
END DFS()
What are the applications of DFS algorithm?
In computer science, applications of this type arise in instruction scheduling, ordering of
formula cell evaluation when recomputing formula values in spreadsheets, logic
synthesis, determining the order of compilation tasks to perform in make files, data
serialization, and resolving symbol dependencies in linkers