Depth First Search, Breadth First Search and Best First Search

Post on 16-Apr-2017

284 views 13 download

transcript

DFSDFS

1

Queue Visited

S

A

B

D

C

G

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

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

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

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

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

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

DFS – Method 2DFS – Method 2

8

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

DFS – Method 2DFS – Method 2

9

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

DFS – Method 2DFS – Method 2

10

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

DFS – Method 2DFS – Method 2

11

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

44

DFS – Method 2DFS – Method 2

12

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

44

55

DFS – Method 2DFS – Method 2

13

S

A

B

D

C

G

Visited and ExpandedVisited and Expanded

VisitedVisited

11

22

33

44

55

BFSBFS

14

Queue Visited

1 (S) SS

A

B

D

C

G

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

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

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

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

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

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

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

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

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

BFSBFS

23

S

A

B

D

C

G

11

22

33

44

55

66

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

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

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

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

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

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