Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
57 views15 pages

Advanced KR 2

The document discusses Uniform Cost Search and A* Search algorithms, highlighting their use of priority queues to find the least cost paths in a graph. It provides examples illustrating the step-by-step process of each algorithm, including how costs are calculated and how nodes are prioritized. Additionally, it notes that while A* is effective, it does not always guarantee the shortest path due to its reliance on heuristics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views15 pages

Advanced KR 2

The document discusses Uniform Cost Search and A* Search algorithms, highlighting their use of priority queues to find the least cost paths in a graph. It provides examples illustrating the step-by-step process of each algorithm, including how costs are calculated and how nodes are prioritized. Additionally, it notes that while A* is effective, it does not always guarantee the shortest path due to its reliance on heuristics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Advanced

Knowledge
Representation
Section 4
Uniform Cost Search
• It is a modification for BFS algorithm.
• Use a priority queue (least cost first)
• Pop the element with least cost
• If two elements have the same cost, use the alphabetic order
Uniform Cost Search (Example
1)

A 4
2 G
2
C
S 5
1
5
3 D
B 4
Uniform Cost Search
• Solution
Priority Queue Current
]S[
]0[
]S,D[ ]S,B[ ]S,A[ ]S[
]5[ ] 3[ ] 2 [ ]0[
]S,A,C[ ]S,D[ ]S,B[ ]S,A[
]6[ ] 5[ ] 3 [ ]2[
]S,B,D[ ]S,A,C[ ]S,D[ ]S,B[
]7[ ] 6[ ] 5[ ]3[
]S,D,G[ ]S,B,D[ ]S,A,C[ ]S,D[
]10[ ] 7[ ] 6[ ]5[
]S,A,C,D[ ]S,D,G[ ]S,B,D [ ]S,A,C[
]S,A,C,G[ ]6[
]8[ ] 7[ ]10[ ] 7[
Uniform Cost Search (Example
2)
Uniform Cost Search (Example
2)
• Solution
Priority Queue Current
]a[
]0[
]a,c[ ]a,b[ ]a[
]3[ ]6[ ]0[
]a,c,e[ ]a,c,d[ ]a,b[ ]a,c[
]5[ ]11[ ]6[ ]3[
]a,c,e,d[ ]a,c,d[ ]a,b[ ]a,c,e[
]14[ ]11[ ]6[ ]5[
]a,b,d[ ]a,c,e,d[ ]a,c,d[ ]a,b[
] 8[ ]14[ ]11[ ]6[
]a,b,d[
]8[
A Star Search
• Solution Idea
• Use a priority queue (like Uniform-cost-search).
• A* algorithm extends the path that minimizes the following function:

f(n)=g(n)+h(n)
• where n is the last node in the path, g(n) is the cost of the path from start node to

node n, h(n) is a heuristic function that estimates cost of the cheapest path
from node n to the goal node.
A Star Search
• Pop the element with least F-cost.

• If two elements have the same F-cost, use alphabetic order.

• Remember: If a node has been visited, we don’t expand it again.


A Star Search (Example 1)
• Use algorithm to find the path between S and G
Heuristic Data
H Node
A 12
1 S
7
5
S 2 A
C G 6
3
4 B
4 2
B
2 C

0 G
A Star Search (Example 1)
• Definitions
Assume the following path S->A->C:
• G-Cost: The cost to move from S to A to C (G-cost=1+5=6)
• H-Cost: The H value for the last node on the path C from the given table (H-
Cost=2)
• F-Cost: G-Cost+ H-Cost=6+2=8 ()
A Star Search (Example 1)
• Solution
Priority Queue Current
The Solution is
]s[
]7[ S->A->B->C->G
]S,B[ ]S,A[ ]s[
]8[ ] 7[ ]7[
]S,A,G[ ]S,A,C[ ]S,A,B[ ]S,B[ ]S,A[
]13[ ] 8[ ] 7[ ] 8[ ]7 [
]S,A,B,C[ ]S,A,G[ ]S,A,C[ ]S,B[ ]S,A,B[
] 7[ ]13[ ] 8[ ] 8[ ]7 [
]S,A,B,C,G[ ]S,A,G[ ]S,A,C[ ]S,B[ ]S,A,B,C[
]8[ ]13[ ] 8[ ] 8[ ]7[
]S,A,B,C,G[
]8[
A Star Search (Example 2)
• Find the most cost-effective path to reach from start node A to the
final node J.
A Star Search (Example 2)
• The numbers written on edges represent the distance between the
nodes.
• The numbers written on nodes represent the heuristic value.
A Star Search (Example 2)
• Solution
Priority Queue Current
The Solution is
]A[
]10[ A->F->G->I->J
]A,F[ ]A,B[ ]A[
]9[ ]14[ ]10[
]A,F,H[ ]A,F,G[ ]A,B[ ]A,F[
]13[ ]9[ ]14[ ]9 [
]A,F,G,I[ ]A,F,H[ ]A,B[ ]A,F,G[
]8[ ]13[ ]14[ ]9 [
]A,F,G,I,E[ ]A,F,H[ ]A,B[ ]A,F,G,I[
]A,F,G,I,J[ ]8[
]10[ ]15[ ]13[ ]14[
]A,F,G,I,J[
]10[
Important Notes
• A* Algorithm is one of the best finding algorithms.
• But it does not produce the shortest path always.
• This is because it heavily depends on heuristics.

You might also like