0% found this document useful (0 votes)
34 views5 pages

Data Structures & Algorithms / Data Structures Hamdard University

The document discusses the breadth-first search (BFS) graph algorithm. It begins by explaining that BFS inspects all neighboring nodes of the root node first before moving to the next level. It then provides the algorithm for BFS which uses a queue to keep track of discovered vertices and colors them white, gray, and black to mark their status in the search. Finally, it lists writing a BFS program for a binary tree as a lab task.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views5 pages

Data Structures & Algorithms / Data Structures Hamdard University

The document discusses the breadth-first search (BFS) graph algorithm. It begins by explaining that BFS inspects all neighboring nodes of the root node first before moving to the next level. It then provides the algorithm for BFS which uses a queue to keep track of discovered vertices and colors them white, gray, and black to mark their status in the search. Finally, it lists writing a BFS program for a binary tree as a lab task.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Data Structures & Algorithms / Data Structures

Hamdard University

LAB SESSION 14
GRAPH ALGORITHM: BREADTH FIRST SEARCH
Objectives:
To understand the concept of breadth first search algorithm.
To understand the implementation of graphs.

Breadth-first search
In graph theory, breadth-first search (BFS) is a strategy for searching in a graph when
search is limited to essentially two operations: (a) visit and inspect a node of a graph;
(b) gain access to visit the nodes that neighbor the currently visited node. The BFS
begins at a root node and inspects all the neighboring nodes. Then for each of those
neighbor nodes in turn, it inspects their neighbor nodes which were unvisited, and so
on

Data Structures & Algorithms / Data Structures


Hamdard University

Algorithm for BFS:

Data Structures & Algorithms / Data Structures


Hamdard University

Q: a queue of discovered vertices


color[v]: color of v
d[v]: distance from s to v
[u]: predecessor of v
white: undiscovered
gray: discovered
black: finished

Data Structures & Algorithms / Data Structures


Hamdard University

Data Structures & Algorithms / Data Structures


Hamdard University

Lab Task
1. Write a program that implements BFS algorithm for binary tree..

You might also like