Docsity

Graph Search: Understanding Breadth-First Search (BFS) and Depth-First Search (DFS), Study Guides, Projects, Research of Communication

Partial preview of the text

Download Graph Search: Understanding Breadth-First Search (BFS) and Depth-First Search (DFS) and more Study Guides, Projects, Research Communication in PDF only on Docsity!

GRAPH SEARCH

BFS & DFS

By: Parminder Benipal

Usage

2 ! Transportation networks (airline carrier, airports as node and direct flights as edges (direct edge). ! Communication networks (a collection of computers as nodes and the physical link between them as edges). ! Information networks (World Wide Web can be viewed as directed graph, the Web pages are nodes and the hyperlink between the pages are directed edges). ! Social Network (People are nodes and friendship is an edge).

C

G H

S

D

E

F

B

A

4

C

G H

S

D

E

F

B

A

5

C

G H

S

D

E

F

B

A

7

C

G H

S

D

E

F

B

A

8

C

G H

S

D

E

F

B

A

10

C

G H

S

D

E

F

B

A

11

C

G H

S

D

E

F

B

A

13

C

G H

S

D

E

F

B

A

14

C

G H

S

D

E

F

B

A

{A B S C G D E F H}

16

Tree after BFS run

C G

H

S

D E F

B

A

17

BFS running time

  1. If we represent the graph G by adjacency matrix then the running time of BFS algorithm is O(n ), where n is the number of nodes.
  2. If we represent the graph G by link lists then the running time of BFS algorithm is O(m + n), where m is the number of edges and n is the number of nodes. 19 2

BFS Applications

! Breadth-first search can be used to solve many problems in graph theory, for example: ¤ Finding all nodes within one connected component ¤ Finding the shortest path between two nodes u and v ¤ Finding the diameter of a graph (seen in assignment). ¤ Testing a graph for bipartiteness (how ?). If there are two vertices x,y in the same level (layer) L_i that are adjacent then the graph is not bipartite. ¤ More… 20