depth first search and breadth first searching

8
Welcome To Data Structure Presentation CSE-134 Submitted by Mohammad Kawsar Hamid Submitted to Kawser Wajed Nafi ID:131-15-2223 Daffodil International University

Upload: sumon-jr

Post on 17-Aug-2015

86 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Depth first search and breadth first searching

Welcome To Data Structure Presentation

CSE-134

Submitted by Mohammad Kawsar Hamid Submitted to Kawser Wajed Nafi ID:131-15-2223 Daffodil International

University

Page 2: Depth first search and breadth first searching

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.

Page 3: Depth first search and breadth first searching

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

Page 4: Depth first search and breadth first searching

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

Page 5: Depth first search and breadth first searching

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.

Page 6: Depth first search and breadth first searching

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

Page 7: Depth first search and breadth first searching

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

Page 8: Depth first search and breadth first searching

The End. Thanks to all.