Professional Documents
Culture Documents
SEARCH
BFS
Breadth-first search
ITERATION
A
B F G
C D H
Queue: { }
A
B F G
C D H
Queue: { A }
A
B F G
C D H
B F G
C D H
Queue: { } dequeue node A to be able to process its neighbours à visit all the children, if a node is
unvisited then enqueue it !!!
A
B F G
C D H
B F G
C D H
B F G
C D H
B F G
C D H
Queue: { G F B } dequeue the next node à it is B and visit its children + put them into the queue
if necessary
A
B F G
C D H
Queue: { G F } dequeue the next node à it is G and visit its children + put them into the queue
if necessary
A
B F G
C D H
Queue: { C G F } dequeue the next node à it is G and visit its children + put them into the queue
if necessary
A
B F G
C D H
Queue: { D C G F } dequeue the next node à it is G and visit its children + put them into the queue
if necessary
A
B F G
C D H
Queue: { D C G F }
A
B F G
C D H
Queue: { D C G }
A
B F G
C D H
Queue: { D C G }
A
B F G
C D H
Queue: { D C }
A
B F G
C D H
Queue: { H D C }
A
B F G
C D H
Queue: { H D C }
A
B F G
C D H
Queue: { H D }
A
B F G
C D H
Queue: { H D }
A
B F G
C D H
Queue: { H }
A
B F G
C D H
Queue: { E H }
A
B F G
C D H
Queue: { E H }
A
B F G
C D H
Queue: { E }
A
B F G
C D H
Queue: { E }
A
B F G
C D H
B F G
C D H
E
Summary
A
B F G
C D H
E
Summary
A
B F G
C D H
E
Summary
A
B F G
C D H
E
Summary
A
B F G
C D H
E
Applications
dfs(vertex) dfs(vertex)
RECURSION ITERATION
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
B F G
C D H
E
Recursively check every
unmarked vertices!
FINISHED
A
B F G
C D H
u Topological ordering
u Kosaraju algorithm for finding strongly connected components in a
graph which can be proved to be very important in
recommendation systems ( youtube )
u Detecting cycles ( checking whether a graph is a DAG or not )
u Generating mazes OR finding way out of a maze
Revisiting breadth-first search
B F G
C D H
E
Revisiting breadth-first search
B F G
C D H
E
Revisiting breadth-first search
B F G
C D H
E
Revisiting breadth-first search
B F G
C D H
E
Revisiting breadth-first search
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H
E
Symmetry in DFS
We can go to the opposite direction,
it is going to be a valid DFS as well !!! A
B F G
C D H