0% found this document useful (0 votes)
53 views50 pages

Breadth First Search

Breadth First Search (BFS) is a graph search algorithm that begins at a starting node and explores all neighboring nodes. It uses a FIFO queue to keep track of discovered nodes and explores each level of the graph completely before moving to the next level. The document shows an example of applying BFS to a graph starting from node A, visiting neighbors level-by-level and keeping discovered nodes in a queue until the search is complete.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
53 views50 pages

Breadth First Search

Breadth First Search (BFS) is a graph search algorithm that begins at a starting node and explores all neighboring nodes. It uses a FIFO queue to keep track of discovered nodes and explores each level of the graph completely before moving to the next level. The document shows an example of applying BFS to a graph starting from node A, visiting neighbors level-by-level and keeping discovered nodes in a queue until the search is complete.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 50

Breadth First Search

A B C D

front

FIFO Queue

Breadth First Search

A B C D

enqueue source node

front

A
FIFO Queue

Breadth First Search

A B C D

dequeue next vertex

front

A
FIFO Queue

Breadth First Search

A B C D

visit neighbors of A

front

FIFO Queue

Breadth First Search

A B C D

visit neighbors of A

front

FIFO Queue

Breadth First Search

A
B C D

B discovered

front

B
FIFO Queue

Breadth First Search

A
B C D

visit neighbors of A

front

B
FIFO Queue

Breadth First Search

A
B C D

I discovered

front

B I
FIFO Queue

Breadth First Search

A
B C D

finished with A

front

B I
FIFO Queue

Breadth First Search

A
B C D

dequeue next vertex

front

B I
FIFO Queue

Breadth First Search

A
B C D

visit neighbors of B

front

I
FIFO Queue

Breadth First Search

A
B C D

visit neighbors of B

front

I
FIFO Queue

Breadth First Search

A
B C D

B
I

F discovered

front

I F
FIFO Queue

Breadth First Search

A
B C D

B
I

visit neighbors of B

front

I F
FIFO Queue

Breadth First Search

A
B C D

B
I

A already discovered

front

I F
FIFO Queue

Breadth First Search

A
B C D

B
I

finished with B

front

I F
FIFO Queue

Breadth First Search

A
B C D

B
I

dequeue next vertex

front

I F
FIFO Queue

Breadth First Search

A
B C D

B
I

visit neighbors of I

front

F
FIFO Queue

Breadth First Search

A
B C D

B
I

visit neighbors of I

front

F
FIFO Queue

Breadth First Search

A
B C D

B
I

A already discovered

front

F
FIFO Queue

Breadth First Search

A
B C D

B
I

visit neighbors of I

front

F
FIFO Queue

Breadth First Search

A
B C D

I
I

E discovered

front

F E
FIFO Queue

Breadth First Search

A
B C D

I
I

visit neighbors of I

front

F E
FIFO Queue

Breadth First Search

A
B C D

I
I

F already discovered

front

F E
FIFO Queue

Breadth First Search

A
B C D

I
I

I finished

front

F E
FIFO Queue

Breadth First Search

A
B C D

I
I

dequeue next vertex

front

F E
FIFO Queue

Breadth First Search

A
B C D

I
I

visit neighbors of F

front

E
FIFO Queue

Breadth First Search

A
B C D

I
I

G discovered

front

E G
FIFO Queue

Breadth First Search

A
B C D

I
I

F finished

front

E G
FIFO Queue

Breadth First Search

A
B C D

I
I

dequeue next vertex

front

E G
FIFO Queue

Breadth First Search

A
B C D

I
I

visit neighbors of E

front

G
FIFO Queue

Breadth First Search

A
B C D

I
I

E finished

front

G
FIFO Queue

Breadth First Search

A
B C D

I
I

dequeue next vertex

front

G
FIFO Queue

Breadth First Search

A
B C D

I
I

visit neighbors of G

front

FIFO Queue

Breadth First Search

A
B

G
C D

I
I

C discovered

front

C
FIFO Queue

Breadth First Search

A
B

G
C D

I
I

visit neighbors of G

front

C
FIFO Queue

Breadth First Search

A
B

G
C D

I
I

H discovered

front

C H
FIFO Queue

Breadth First Search

A
B

G
C D

I
I

G finished

front

C H
FIFO Queue

Breadth First Search

A
B

G
C D

I
I

dequeue next vertex

front

C H
FIFO Queue

Breadth First Search

A
B

G
C D

I
I

visit neighbors of C

front

H
FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

D discovered

front

H D
FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

C finished

front

H D
FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

get next vertex

front

H D
FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

visit neighbors of H

front

D
FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

finished H

front

D
FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

dequeue next vertex

front

D
FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

visit neighbors of D

front

FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

D finished

front

FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

dequeue next vertex

front

FIFO Queue

Breadth First Search

A
B

G
C

C
D

I
I

STOP

front

FIFO Queue

You might also like