Artificial intelligence Depth First Search

NOUMANSULEMAN1 134 views 21 slides Jul 08, 2020
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

Soory Only Slides .


Slide Content

Artificial Intelligence Presentation Topic Depth First Search

Introduction Name : Nouman Roll No : 17-Ntu-1236 Program : BSIT

Depth-first search   it is an algorithm for traversing or searching tree or graph data structures. One starts at the root and explores as far as possible along each branch before backtracking. A version of depth-first search was investigated in the 19th century French mathematician Charles Pierre Tremaux as a strategy for solving mazes. Depth-first search is a systematic way to find all the vertices reachable from a source vertex. Like breadth-first search, DFS traverse a connected component of a given graph and defines a spanning tree. The basic idea of depth-first search is methodically exploring every edge. We start over from a different vertices as necessary. As soon as we discover a vertex, DFS starts exploring from it (unlike BFS, which puts a vertex on a queue so that it explores from it later).

Basic Points Uninformed Search Uses Stack Phenomenon Deepest Node Incomplete (Possible That DFS didn’t give us result if search space infinite . Move one side till loop not completed) Non optimal (cost High or other cost low) Work on present Knowledge (Not on Estimation value)

Complexity: Each nodes and edges are visited once. So the complexity of DFS is  O(V+E) , where  V  denotes the number of nodes and  E  denotes the number of edges.

Applications of Depth First Search: Finding all pair shortest path in an undirected graph. Detecting cycle in a graph. Path finding. Topological Sort. Testing if a graph is bipartite. Finding Strongly Connected Component. Solving puzzles with one solution .

Rules For Traverse graph Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty.

Let's look at an example. We'll traverse this graph: Stack

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : AB A B

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABE A B E

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEF A B F

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEF A B

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEF A

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEFC A C

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEFCG A C G

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEFCG A

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEFCGD A D

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEFCGD A D H

Let's look at an example. We'll traverse this graph: Stack Rule #1 Put the starting vertex into the stack. Mark it visited Display it. Rule #2 if(stack{top} has adjacent unvisited vertex) { Visit adjacent unvisited vertex and mark it visited push it into stack display it. } Else { Pop top element of stack. } Repeat Rule 2 until stack is empty. Display : ABEFCGD