You are on page 1of 12

Artificial Interligence

in FinTech
Dr. Dinh Chi HIEU

Jan 15th, 2024


Breadth-First Search
Algorithm
Breadth-First Search is a graph search algorithm that can be
used to solve a variety of problems such as:
• finding all the vertices reachable from a vertex
• finding if an undirected graph is connected
• finding the shortest path from one vertex to all other vertices
• to determine if a graph is bipartite
• to bond the diameter of an undirected graph
• partitioning the graph

Process of Breadth-First Search Algorithm


Breadth-First Search
Algorithm
1.Visiting a node: select a node.
2.Exploring a node: Exploring the adjacent nodes (child nodes) of a selected node.
Breadth-First Search
Algorithm

Step 1: Take an Empty Queue.


Step 2: Select a starting node (visiting a node) and insert it into
the Queue.
Step 3: Provided that the Queue is not empty, extract the node
from the Queue and insert its child nodes (exploring a node)
into the Queue.
Step 4: Print the extracted node.
Breadth-First Search
Algorithm - Pseudocode
Breadth-First Search
Algorithm
Step1: Initially queue and visited arrays are empty

Step2: Push node 0 into queue and mark it visited.


Breadth-First Search
Algorithm
Step 3: Remove node 0 from the front of queue and visit the
unvisited neighbours and push them into queue

Step 4: Remove node 1 from the front of queue and visit the
unvisited neighbours and push them into queue
Breadth-First Search
Algorithm
Step 5: Remove node 2 from the front of queue and visit the
unvisited neighbours and push them into queue

Step 6: Remove node 3 from the front of queue and visit the
unvisited neighbours and push them into queue
Breadth-First Search
Algorithm

Steps 7: Remove node 4 from the front of queue and visit the
unvisited neighbours and push them into queue

Now, Queue becomes empty, So, terminate these process of iteration.

BFS(2) = 2 0 1 4 3
Breadth-First Search
Python implementation
Breadth-First Search
Python implementation
Depth-First Search
Python implementation

You might also like