Workedout-Example-Search-Algorithms
Workedout-Example-Search-Algorithms
B 75 D 140 J 118
C 71 P 80 E 99 K 111
P 80 E 99 G 101 F 85 H 90 M 75
97 Q 97 N G 211 N 120
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)
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