depth first search and breadth first searching
TRANSCRIPT
Welcome To Data Structure Presentation
CSE-134
Submitted by Mohammad Kawsar Hamid Submitted to Kawser Wajed Nafi ID:131-15-2223 Daffodil International
University
Depth First Search1.Depth first search was first investigated by
French Mathematician Charles Pierre tremaux.2.It is an algorithm for traversing tree or graph
data structures.3.One starts at the root and explores as deep as
possible along each branch before backtracking.
4.It can be implemented using stack.
Depth-first searching A depth-first search
(DFS) explores a path all the way to a leaf before backtracking and exploring another path.
For example, after searching A, then B, then D, the search backtracks and tries another path from B.
Node are explored in the order A B D E H L M N I O P C F G J K Q.
N will be found before J.
L M N O P
G
Q
H JI K
FED
B C
A
1.In Depth first search edges are explored out of the most recently dis-covered vertex. Only edges to unexplored vertices are explored.2.When all of vertices edges have been explored, the search “back-tracks” to explore edges leaving the vertex from which vertex was discovered.3.The process continues until we have discovered all the vertices that are reachable from the original source vertex.4.If any undiscovered vertices remain, then one of them is selected as a new source vertex.5.This process if repeated until all vertices are discovered.
Idea of The Depth First Search Algorithm
Breadth First Search
1.The Breadth first search begins at a root node and inspects all the neighboring nodes.
2.Then for each of those neighbor nodes in turn, it inspects their neighbor nodes which were unvisited,
and so on.3.It can be implemented using queue.
Breadth First Searching
A breadth-first search (BFS) explores nodes nearest the root before exploring nodes further away.
For example, after searching A, then B, then C, the search proceeds with D, E, F, G.
Node are explored in the order A B C D E F G H I J K L M N O P Q.
J will be found before N.
L M N O P
G
Q
H JI K
FED
B C
A
Enqueue the root node Dequeue a node and examine it
If the element sought is found in this node, quit the search and return a result.
Otherwise enqueue any successors (the direct child nodes) that have not yet been discovered.
If the queue is empty, every node on the graph has been examined – quit the search and return "not found".
If the queue is not empty, repeat from Step 2.
Idea of Breadth First Search
The End. Thanks to all.