Top Banner
DFS DFS 1 Queue Visited S A B D C G
29

Depth First Search, Breadth First Search and Best First Search

Apr 16, 2017

Download

Engineering

Adri Jovin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Depth First Search, Breadth First Search and Best First Search

DFSDFS

1

Queue Visited

S

A

B

D

C

G

Page 2: Depth First Search, Breadth First Search and Best First Search

DFSDFS

2

Queue Q Visited

1 (S) SS

A

B

D

C

G

Pick the first element of Q and add path extension to the front of Q

11

Page 3: Depth First Search, Breadth First Search and Best First Search

DFSDFS

3

Queue Q Visited

1 (S) S

2 (A S) (B S) A, B, SS

A

B

D

C

G

Pick the first element of Q and add path extension to the front of Q

11

22

Page 4: Depth First Search, Breadth First Search and Best First Search

DFSDFS

4

Queue Q Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (C A S) (D A S) (B S)

C, D, B, A, S

S

A

B

D

C

G

Pick the first element of Q and add path extension to the front of Q

11

22

33

Page 5: Depth First Search, Breadth First Search and Best First Search

DFSDFS

5

Queue Q Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (C A S) (D A S) (B S) C, D, B, A, S

4 (D A S) (B S) C, D, B, A, S

S

A

B

D

C

G

Pick the first element of Q and add path extension to the front of Q

11

22

33

44

Page 6: Depth First Search, Breadth First Search and Best First Search

DFSDFS

6

Queue Q Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (C A S) (D A S) (B S) C, D, B, A, S

4 (D A S) (B S) C, D, B, A, S

5 (G D A S) (B S) G,C,D,B,A,S

S

A

B

D

C

G

Pick the first element of Q and add path extension to the front of Q

11

22

33

44

55

Page 7: Depth First Search, Breadth First Search and Best First Search

DFSDFS

7

Queue Q Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (C A S) (D A S) (B S) C, D, B, A, S

4 (D A S) (B S) C, D, B, A, S

5 (G D A S) (B S) G,C,D,B,A,S

S

A

B

D

C

G

Pick the first element of Q and add path extension to the front of Q

11

22

33

44

55

Page 8: Depth First Search, Breadth First Search and Best First Search

DFS – Method 2DFS – Method 2

8

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

Page 9: Depth First Search, Breadth First Search and Best First Search

DFS – Method 2DFS – Method 2

9

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

Page 10: Depth First Search, Breadth First Search and Best First Search

DFS – Method 2DFS – Method 2

10

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

Page 11: Depth First Search, Breadth First Search and Best First Search

DFS – Method 2DFS – Method 2

11

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

44

Page 12: Depth First Search, Breadth First Search and Best First Search

DFS – Method 2DFS – Method 2

12

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

44

55

Page 13: Depth First Search, Breadth First Search and Best First Search

DFS – Method 2DFS – Method 2

13

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

44

55

Page 14: Depth First Search, Breadth First Search and Best First Search

BFSBFS

14

Queue Visited

1 (S) SS

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

Page 15: Depth First Search, Breadth First Search and Best First Search

BFSBFS

15

Queue Visited

1 (S) S

2 (A S) (B S) A, B, SS

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

Page 16: Depth First Search, Breadth First Search and Best First Search

BFSBFS

16

Queue Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (B S) (CAS) (DAS) C,D,B,A,S

S

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

22

Page 17: Depth First Search, Breadth First Search and Best First Search

BFSBFS

17

Queue Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (B S) (CAS) (DAS) C,D,B,A,S

4 (CAS) (DAS) (GBS)* G,C,D,B,A,S

S

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

22

33

Page 18: Depth First Search, Breadth First Search and Best First Search

BFSBFS

18

Queue Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (B S) (CAS) (DAS) C,D,B,A,S

4 (CAS) (DAS) (GBS)* G,C,D,B,A,S

S

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

22

33

*We can stop here, when the first path to the goal is generated

Page 19: Depth First Search, Breadth First Search and Best First Search

BFSBFS

19

Queue Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (B S) (CAS) (DAS) C,D,B,A,S

4 (CAS) (DAS) (GBS)* G,C,D,B,A,S

5 (DAS) (GBS) G,C,D,B,A,S

S

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

22

33

*We can stop here, when the first path to the goal is generated

44

Page 20: Depth First Search, Breadth First Search and Best First Search

BFSBFS

20

Queue Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (B S) (CAS) (DAS) C,D,B,A,S

4 (CAS) (DAS) (GBS)* G,C,D,B,A,S

5 (DAS) (GBS) G,C,D,B,A,S

S

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

22

33

*We can stop here, when the first path to the goal is generated

44

55

Page 21: Depth First Search, Breadth First Search and Best First Search

BFSBFS

21

Queue Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (B S) (CAS) (DAS) C,D,B,A,S

4 (CAS) (DAS) (GBS)* G,C,D,B,A,S

5 (DAS) (GBS) G,C,D,B,A,S

6 (GBS) G,C,D,B,A,S

S

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

22

33

*We can stop here, when the first path to the goal is generated

44

55

66

Page 22: Depth First Search, Breadth First Search and Best First Search

BFSBFS

22

Queue Visited

1 (S) S

2 (A S) (B S) A, B, S

3 (B S) (CAS) (DAS) C,D,B,A,S

4 (CAS) (DAS) (GBS)* G,C,D,B,A,S

5 (DAS) (GBS) G,C,D,B,A,S

6 (GBS) G,C,D,B,A,S

S

A

B

D

C

G

Pick first element of Q, Add path extensions to end of Q

11

22

33

*We can stop here, when the first path to the goal is generated

44

55

66

Page 23: Depth First Search, Breadth First Search and Best First Search

BFSBFS

23

S

A

B

D

C

G

11

22

33

44

55

66

Page 24: Depth First Search, Breadth First Search and Best First Search

Best FirstBest First

24

Queue Visited

1 (10 S) S

S

A

B

D

C

G

Pick “best” (by heuristic value) element of Q, Add path extensions anywhere in Q

A = 2A = 2B = 3B = 3C = 1C = 1D = 4D = 4S = 10S = 10G = 0G = 0

Heuristic Values

Page 25: Depth First Search, Breadth First Search and Best First Search

Best FirstBest First

25

Queue Visited

1 (10 S) S

2 (2 A S) (3 B S) A,B,S S

A

B

D

C

G

Pick “best” (by heuristic value) element of Q, Add path extensions anywhere in Q

A = 2A = 2B = 3B = 3C = 1C = 1D = 4D = 4S = 10S = 10G = 0G = 0

Heuristic Values

11

Page 26: Depth First Search, Breadth First Search and Best First Search

Best FirstBest First

26

Queue Visited

1 (10 S) S

2 (2 A S) (3 B S) A,B,S

3 (1 C A S) (3 B S) (4 D A S) C,D,A,B,S

S

A

B

D

C

G

Pick “best” (by heuristic value) element of Q, Add path extensions anywhere in Q

A = 2A = 2B = 3B = 3C = 1C = 1D = 4D = 4S = 10S = 10G = 0G = 0

Heuristic Values

11

22

Page 27: Depth First Search, Breadth First Search and Best First Search

Best FirstBest First

27

Queue Visited

1 (10 S) S

2 (2 A S) (3 B S) A,B,S

3 (1 C A S) (3 B S) (4 D A S) C,D,A,B,S

4 (3 B S) (4 D A S) C,D,A,B,S

S

A

B

D

C

G

Pick “best” (by heuristic value) element of Q, Add path extensions anywhere in Q

A = 2A = 2B = 3B = 3C = 1C = 1D = 4D = 4S = 10S = 10G = 0G = 0

Heuristic Values

11

22

33

Page 28: Depth First Search, Breadth First Search and Best First Search

Best FirstBest First

28

Queue Visited

1 (10 S) S

2 (2 A S) (3 B S) A,B,S

3 (1 C A S) (3 B S) (4 D A S) C,D,A,B,S

4 (3 B S) (4 D A S) C,D,A,B,S

5 (0 G B S) (4 D A S) G,C,D,B,A,S

S

A

B

D

C

G

Pick “best” (by heuristic value) element of Q, Add path extensions anywhere in Q

A = 2A = 2B = 3B = 3C = 1C = 1D = 4D = 4S = 10S = 10G = 0G = 0

Heuristic Values

11

22

33

44

Page 29: Depth First Search, Breadth First Search and Best First Search

Best FirstBest First

29

Queue Visited

1 (10 S) S

2 (2 A S) (3 B S) A,B,S

3 (1 C A S) (3 B S) (4 D A S) C,D,A,B,S

4 (3 B S) (4 D A S) C,D,A,B,S

5 (0 G B S) (4 D A S) G,C,D,B,A,S

S

A

B

D

C

G

Pick “best” (by heuristic value) element of Q, Add path extensions anywhere in Q

A = 2A = 2B = 3B = 3C = 1C = 1D = 4D = 4S = 10S = 10G = 0G = 0

Heuristic Values

11

22

33

44