0% found this document useful (0 votes)
1 views

Workedout-Example-Search-Algorithms

The document presents a tree diagram representing a map with nodes and their respective distances. It details various search algorithms including Uniform Cost Search, Depth First Search, Breadth-First Search, Greedy-Best First Search, and A* Search, outlining their processes, time complexities, and paths found. Each algorithm's performance is evaluated in terms of optimality and completeness, with specific paths to the goal node G highlighted.

Uploaded by

junejoameen44
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Workedout-Example-Search-Algorithms

The document presents a tree diagram representing a map with nodes and their respective distances. It details various search algorithms including Uniform Cost Search, Depth First Search, Breadth-First Search, Greedy-Best First Search, and A* Search, outlining their processes, time complexities, and paths found. Each algorithm's performance is evaluated in terms of optimality and completeness, with specific paths to the goal node G highlighted.

Uploaded by

junejoameen44
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Tree diagram of the given map

B 75 D 140 J 118

C 71 P 80 E 99 K 111

D 151 Q 97 N 146 G 211 L 70

P 80 E 99 G 101 F 85 H 90 M 75

97 Q 97 N G 211 N 120

G 101 P 146 Q 138

G 101
Straight-line distance to
Node G
A 366
B 374
C 380
D 253
J 329
K 244
L 241
M 242
N 160
P 193
Q 98
G 0
H 77
F 80
E 178
Uniform Cost Search (UCS)
1 Priority Queue: [A]
2 Priority Queue: [B (75), J (118), D (140)] Visited: A
3 Priority Queue: [J (118), D (140), C (75+71=146)] Visited: A, B
4 Priority Queue: [D (140), C (146), K (118+111=229)] Visited: A, B, J
5 Priority Queue: [C (146), P (140+80=220), K (229), E
Visited: A, B, J, D
(140+99=239)]
6 As D (140) with smaller cost has already been
explored. D (146 + 151 = 297) from C (146) will not
be explored. Visited: A, B, J, D, C
Priority Queue: [P (220), K (229), E (239)]
7 Priority Queue: [K (229), E (239), Q (220+97=317),
Visited: A, B, J, D, C, P
N (220+146=366)]
8 Priority Queue: [E (239), Q (317), L (229+111 =
Visited: A, B, J, D, C, P, K
340), N (366)]
9 Priority Queue: [Q (317), L (340), N (366), G
Visited: A, B, J, D, C, P, K, E
(239+211=450)]
10 Priority Queue: [L (340), N (366), G (317+101=418)]
The previous G (450), due to its higher cost, will be
Visited: A, B, J, D, C, P, K, E, Q
replaced by a new node with smaller cost, i.e., G
(418)
11 Priority Queue: [N (366), M (340+75=374), G (418)] Visited: A, B, J, D, C, P, K, E, Q, L
12 N (366) being the leaf node will be discarded. N
(374 + 120 = 494) having the higher cost than N
Visited: A, B, J, D, C, P, K, E, Q, L, G
(366) will also be discarded. Finally, the goal G
(418) is found.
Time Complexity: 12, Space Complexity: 4 memory cells, Optimality: YES, path with the
lowest cost of 418 returned, Complete: YES
Path found: A → D (140) → P (220) → Q (317) → G (418)

Depth First Search (DFS)


1 Stack: [A]
2 Stack: [A, B] Visited: A
3 Stack: [A, B, C] Visited: A, B
4 Stack: [A, B, C, D] Visited: A, B, C
5 Stack: [A, B, C, D, P] Visited: A, B, C, D
6 Stack: [A, B, C, D, P, Q] Visited: A, B, C, D, P
7 Stack: [A, B, C, D, P, Q, G] Goal Found Visited: A, B, C, D, P, Q
Time Complexity: 7, Space Complexity: 7 memory cells, Optimality: NO, path with the
lowest cost of 3 was NOT selected, Complete: YES
Path found: A → B →C → D → P → Q → G
Breadth-First Search (BFS)
1 Queue: [A]
2 Queue: [B, D, J] Visited: A
3 Queue: [D, J, C] Visited: A, B
4 Queue: [J, C, P, E] Visited: A, B, D
Queue: [C, P, E, K] C will be just dequeued as D has
5 Visited: A, B, D, J
already been visited (i.e., C has no new children)
6 Queue: [P, E, K] Visited: A, B, D, J, C
7 Queue: [E, K, Q, N] Visited: A, B, D, J, C, P
8 Queue: [K, Q, N, G] Visited: A, B, D, J, C, P, E
9 Queue: [Q, N, G, L] Visited: A, B, D, J, C, P, E, K
10 Queue: [N, G, L, G] Visited: A, B, D, J, C, P, E, K, Q
11 Queue: [G, L, G] N is the leaf node and is discarded Visited: A, B, D, J, C, P, E, K, Q, N
12 Goal found Visited: A, B, D, J, C, P, E, K, Q, N, G
Time Complexity: 12, Space Complexity: 4 memory cells, Optimality: YES, path with the
lowest cost selected, Complete: YES
Path found: A → D → E → G

Greedy-Best First Search (GBFS)


1 Priority Queue: [A (366)]
2 Priority Queue: [D (253), J (329), B (374)] Visited: A
3 Priority Queue: [E (178), P (193)] Visited: A, D
4 Priority Queue: [G (0)] Goal Found Visited: A, D, E
Time Complexity: 4, Space Complexity: 3 memory cells, Optimality: NO, path with the
lowest cost was NOT selected, Complete: YES (in this case, may NOT be in other case)
Path found: A → D → E → G

A* Search
1 Priority Queue: [A (366)]
2 Priority Queue: [D (253+140 = 393), J (329+118 = Visited: A
447), B (374+75 = 449)]. Expand with the lowest
𝑓(𝑛)
3 Priority Queue: [ P (193+80 = 273), E (178+99 = Visited: A, D
277)]. Expand with the lowest 𝑓(𝑛)
4 Priority Queue: [ Q (97+98 = 197), N (146+160 = Visited: A, D, P
206)]. Expand with the lowest 𝑓(𝑛)
5 Priority Queue: [ G (101+0 = 101)] Goal Found Visited: A, D, P, Q
Time Complexity: 5, Space Complexity: 3 memory cells, Optimality: YES, path with the
lowest cost was selected, Complete: YES
Path found: A → D → P → Q → G

You might also like