0% found this document useful (0 votes)
33 views7 pages

Notre Dame University Bangladesh Artificial Intelligence Breadth First Search

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views7 pages

Notre Dame University Bangladesh Artificial Intelligence Breadth First Search

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Notre Dame University

Bangladesh

Artificial Intelligence
CSE4103
Breadth First Search

Submitted To :
Humayara Binte Rashid
Lecturer
Department of CSE

Submitted By :
Abrity Paul Chowdhury
ID : 0692130005101005
Batch : CSE17

Submission Date : November 5 ,2024


Contents

0.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.2 Key Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.3 Working Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.4 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.5 Applications of BFS . . . . . . . . . . . . . . . . . . . . . . . . . 3
0.6 Real Life Implementation . . . . . . . . . . . . . . . . . . . . . . 3
0.7 Advantages of BFS . . . . . . . . . . . . . . . . . . . . . . . . . . 6
0.8 Limitations of BFS . . . . . . . . . . . . . . . . . . . . . . . . . . 6
0.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1
0.1 Introduction
Breadth First Search (BFS) is a graph traversal algorithm that visits nodes level
by level. It explores the closest vertices first, unlike Depth First Search (DFS).
BFS is used in algorithms like Dijkstra’s and Prim’s and can detect cycles and
find shortest paths in unweighted graphs.

0.2 Key Concepts


BFS uses a queue to keep track of the nodes to visit next. Nodes are visited in
layers: starting from the initial node, BFS explores all directly connected nodes
before moving to those that are further away.

0.3 Working Procedure


The steps involved in BFS are as follows:

Figure :Working Procedure of BFS

0.4 Pseudocode
Input: s as the source node
BFS(G, s):

• Let Q be a queue.
• Q.enqueue(s)
• Mark s as visited
• While (Q is not empty):

– v = Q.dequeue()
– For all neighbors w of v in Graph G:

2
∗ If w is not visited:
· Q.enqueue(w)
· Mark w as visited

0.5 Applications of BFS


BFS is widely used in various applications, including:
• Shortest Path: Finds the shortest path in unweighted graphs.
• Cycle Detection: Identifies cycles by detecting revisited nodes.

• Connected Components: Identifies sets of reachable nodes.


• Topological Sorting: Orders nodes in a Directed Acyclic Graph (DAG).
• Level Order Traversal: Traverses binary trees level by level.

• Network Routing: Finds shortest paths for routing data packets.

0.6 Real Life Implementation


In real life, BFS is widely used in web crawling, where it systematically tra-
verses web pages level by level. The algorithm extracts and categorizes URLs
into internal and external, ensuring comprehensive coverage of a website up to
a specified depth. This method is particularly valuable for web scraping and
data mining, enabling efficient data collection. BFS is also utilized in navigation
systems for finding shortest paths and in social networks for friend recommen-
dations, demonstrating its versatility in handling real-world problems.

Figure:Diagram of Web crawling procedure associated with


BFS

3
The corresponding code

Figure:Web crawling using BFS part 1

4
Figure:Web crawling using BFS part 2

Figure:Web crawling using BFS part 3

Result

Figure:Web crawling using BFS result part 1

5
Figure:Web crawling using BFS result part 2

0.7 Advantages of BFS


• Finds the shortest path in unweighted graphs.
• Easy to implement and understand.
• Systematic and complete traversal, visiting every node level by level.

• Useful for solving problems like shortest path, cycle detection, and con-
nectivity.

0.8 Limitations of BFS


• High memory usage for large graphs.
• Inefficient for deep graphs compared to DFS.
• May be slower compared to Depth-First Search (DFS) for some problems.

0.9 Conclusion
In conclusion, web crawling using BFS is an efficient method to systematically
traverse and extract data from the web. By categorizing URLs into internal and
external links and managing them using a queue, the crawler ensures comprehen-
sive coverage up to a specified depth. This approach is valuable for applications
like web scraping, data mining, and building search engines.

You might also like