Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Graph Theory: Breadth-First Search (BFS) and Depth-First Search (DFS), Lecture notes of Data Structures and Algorithms

An overview of graph searching algorithms, specifically Breadth-First Search (BFS) and Depth-First Search (DFS). It covers the concepts, procedures, and properties of both algorithms, including their differences. BFS explores vertices and edges starting from a specified vertex, looking at vertices closest first, while DFS explores vertices and edges based on the depth of the graph. Both algorithms are essential in understanding graph theory and its applications.

What you will learn

  • How does BFS traverse a graph?
  • What is the ancestor-descendent property in DFS?
  • What is the difference between Breadth-First Search (BFS) and Depth-First Search (DFS) in graph theory?
  • What are the advantages and disadvantages of using BFS and DFS?
  • What data structures are used in BFS and DFS?

Typology: Lecture notes

2019/2020

Uploaded on 11/07/2020

modi-ketul-1
modi-ketul-1 ๐Ÿ‡ฎ๐Ÿ‡ณ

4.7

(3)

12 documents

1 / 62

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Graph Theory- SC322:
BFS & DFS
Graph Theory- SC322: BFS & DFS
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e

Partial preview of the text

Download Graph Theory: Breadth-First Search (BFS) and Depth-First Search (DFS) and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Graph Theory- SC322:

BFS & DFS

Graph searching

Graph seacrhing is the systematic traversal of the vertices and edges of a graph in order to learn useful structural properties of a graph.

Graph searching

Graph seacrhing is the systematic traversal of the vertices and edges of a graph in order to learn useful structural properties of a graph. Graph searching techniques are central to several important graph algorithms. Many advanced algorithms begin by a graph searching routine before proceeding with other computations. The two most common graph searching algorithms are Breadth-First Search (BFS) and Depth-First Search (DFS).

BFS explores the edges and vertices of a graph starting from a specified vertex by looking at vertices closest first and then moving to remote vertices. It performs explorations at all vertices at a distance k from the source before looking at any vertex before doing so for any vertex at distance k + 1.

BFS explores the edges and vertices of a graph starting from a specified vertex by looking at vertices closest first and then moving to remote vertices. It performs explorations at all vertices at a distance k from the source before looking at any vertex before doing so for any vertex at distance k + 1.

DFS explores further and deeper along a path until no further progress is possible and then retraces and branches from an earlier point.

During their course both these algorithms get useful information about the graph. They are used either directly or as prototypes to develop subroutines for many graph algorithms.

BFS (G,s)

(^1) for each vertex u โˆˆ V [G ] \ {s}

BFS (G,s)

(^1) for each vertex u โˆˆ V [G ] \ {s} (^2) do colour [u] โ† white (^3) d[u] โ† โˆž

BFS (G,s)

(^1) for each vertex u โˆˆ V [G ] \ {s} (^2) do colour [u] โ† white (^3) d[u] โ† โˆž (^4) ฯ€[u] โ† nil

BFS (G,s)

(^1) for each vertex u โˆˆ V [G ] \ {s} (^2) do colour [u] โ† white (^3) d[u] โ† โˆž (^4) ฯ€[u] โ† nil (^5) colour [s] โ† grey (^6) d[s] โ† s

BFS (G,s)

(^1) for each vertex u โˆˆ V [G ] \ {s} (^2) do colour [u] โ† white (^3) d[u] โ† โˆž (^4) ฯ€[u] โ† nil (^5) colour [s] โ† grey (^6) d[s] โ† s (^7) ฯ€[s] โ† nil

BFS (G,s)

(^1) for each vertex u โˆˆ V [G ] \ {s} (^2) do colour [u] โ† white (^3) d[u] โ† โˆž (^4) ฯ€[u] โ† nil (^5) colour [s] โ† grey (^6) d[s] โ† s (^7) ฯ€[s] โ† nil (^8) Q โ† โˆ… (^9) ENQUEUE (Q, s)

(^10) while (Q 6 = โˆ…)

(^10) while (Q 6 = โˆ…)

(^11) do u โ† DEQUEUE (Q)

(^12) for each v โˆˆ Adj[u]

(^10) while (Q 6 = โˆ…)

(^11) do u โ† DEQUEUE (Q)

(^12) for each v โˆˆ Adj[u]

(^13) do if colour [v ] = white