0% found this document useful (0 votes)
35 views

Lecture 13.1

This document provides an overview of breadth-first search (BFS) on graphs. It defines BFS as visiting the start vertex and putting it in a queue, then repeatedly removing vertices from the queue and visiting/queueing unvisited neighbors. An example applying BFS to a sample graph is shown step-by-step. Applications of BFS like shortest paths, social networks, and more are listed. Recommended books on data structures and algorithms are also provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Lecture 13.1

This document provides an overview of breadth-first search (BFS) on graphs. It defines BFS as visiting the start vertex and putting it in a queue, then repeatedly removing vertices from the queue and visiting/queueing unvisited neighbors. An example applying BFS to a sample graph is shown step-by-step. Applications of BFS like shortest paths, social networks, and more are listed. Recommended books on data structures and algorithms are also provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Graph Traversing and Searching

Course Code: CSC 2106 Course Title: Data Structure (Theory)

Dept. of Computer Science


Faculty of Science and Technology

Lecture No: 13.1 Week No: 13 Semester: Fall 2020-2021


Lecturer: MAHFUJUR RAHMAN, [email protected]
Lecture Outline

1. Breadth-First-Search (BFS)
2. BFS Example
Breadth-First Search (BFS)

 Visit
 start vertex and put into a FIFO queue.
 Repeatedly
 remove a vertex from the queue,
 visit its unvisited adjacent vertices,
 put newly visited vertices into the queue.
Breadth-First Search Example

2
3
8
1

4
5
9

6
7

Start search at vertex 1.


2 FIFO Queue
3 1
8
1

4
5
9

6
7

Visit/mark/label start vertex and put in a FIFO queue.


2 FIFO Queue
3 1
8
1

4
5
9

6
7

Remove 1 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
2 4
8
1

4
5
9

6
7

Remove 1 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
2 4
8
1

4
5
9

6
7

Remove 2 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
4 5 3 6
8
1

4
5
9

6
7

Remove 2 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
4 5 3 6
8
1

4
5
9

6
7

Remove 4 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
5 3 6
8
1

4
5
9

6
7

Remove 4 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
5 3 6
8
1

4
5
9

6
7

Remove 5 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
3 6 9 7
8
1

4
5
9

6
7

Remove 5 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
3 6 9 7
8
1

4
5
9

6
7

Remove 3 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
6 9 7
8
1

4
5
9

6
7

Remove 3 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
6 9 7
8
1

4
5
9

6
7

Remove 6 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
9 7
8
1

4
5
9

6
7

Remove 6 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
9 7
8
1

4
5
9

6
7

Remove 9 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
7
88
1

4
5
9

6
7

Remove 9 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
7 8
8
1

4
5
9

6
7

Remove 9 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
7 8
8
1

4
5
9

6
7

Remove 7 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
8
8
1

4
5
9

6
7

Remove 7 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
8
8
1

4
5
9

6
7

Remove 8 from Q; visit adjacent unvisited vertices; put in Q.


2 FIFO Queue
3
8
1

4
5
9

2
3
8
6 1
7
4
5
9

Queue is empty. Search terminates.


6
7
Applications of Breadth First Search

 To find Shortest Path and Minimum Spanning Tree for unweighted graph
 To find all neighbor nodes in Peer to Peer Networks.
 Crawlers in Search Engines
 Social Networking Websites
 GPS Navigation systems
 Broadcasting in Network
 In Garbage Collection
 Cycle detection in undirected graph:
 Finding all nodes within one connected component:
 Ford–Fulkerson algorithm
 To test if a graph is Bipartite
 Path Finding
Books

 “Schaum's Outline of Data Structures with C++”. By John R. Hubbard (Can be


found in university Library)
 “Data Structures and Program Design”, Robert L. Kruse, 3rd Edition, 1996.
 “Data structures, algorithms and performance”, D. Wood, Addison-Wesley, 1993
 “Advanced Data Structures”, Peter Brass, Cambridge University Press, 2008
 “Data Structures and Algorithm Analysis”, Edition 3.2 (C++ Version), Clifford A.
Shaffer, Virginia Tech, Blacksburg, VA 24061 January 2, 2012
 “C++ Data Structures”, Nell Dale and David Teague, Jones and Bartlett Publishers,
2001.
 “Data Structures and Algorithms with Object-Oriented Design Patterns in C++”,
Bruno R. Preiss,
References

1. https://en.wikipedia.org/wiki/Data_structure
2. https://visualgo.net/en/dfsbfs?slide=1

You might also like