CSCI323 – Modern AI Uniform Cost Search Example Uniform Cost Search (UCS) • Uniform Cost Search (UCS) is a search algorithm used to find the least cost path from a start node to a goal node in a weighted graph. • It is an uninformed algorithm, that is, it does not have prior information about the path or nodes. • it is optimal and complete, that is, it will always find the least cost path if one Uniform Cost Search (UCS) UCS Algorithm Steps: 1.Initialize: • Create a priority queue and insert the start node with a cost of 0. • Create a set to keep track of visited nodes. Uniform Cost Search (UCS) 2.Expand Nodes: • While the priority queue is not empty: • Dequeue the node with the lowest cumulative cost. • If this node is the goal, return the path and the total cost. Uniform Cost Search (UCS) • If this node has not been visited: • Mark it as visited. • For each neighbouring node, calculate the cumulative cost and enqueue the neighbour with this cost if it has not been visited or if a lower cost path to it is found. Uniform Cost Search (UCS) 3.Goal Check: • If the goal node is reached, the path and its cost are returned. • If the priority queue is empty and the goal has not been reached, there is no path to the goal. Example Sta rt A 1 4 C 1 A B D Candidat Frontier Visited e (Min Heap) 2 B C 5 D E E Example Candidate π΄ π΅ πΆ π· πΈ Frontier (Min Heap) Visited Example Candidate Frontier (Min Heap) π΄ π΄0 π΅ πΆ π· πΈ Visited Example Candidate Frontier (Min Heap) π΄ π΄0 π΅ πΆ π· πΈ πΆ4 π΅1 Visited Example Candidate Frontier (Min Heap) Visited π΄ π΅1 π΄0 π΅ πΆ π· πΈ πΆ4 Example Candidate Frontier (Min Heap) Visited π΄ π΅1 π΄0 π΅ πΆ π· πΈ πΆ4 π·3 Example Candidate Frontier (Min Heap) Visited π΄ π·3 π΄0 π΅ πΆ π· πΈ πΆ4 π΅1 Example Candidate Frontier (Min Heap) Visited π΄ π·3 π΄0 π΅ πΆ π· πΈ πΆ4 πΈ8 π΅1 Example Candidate Frontier (Min Heap) Visited π΄ πΆ4 π΄0 π΅ πΈ8 π΅1 πΆ π· πΈ π·3 Example Candidate Frontier (Min Heap) Visited π΄ πΈ8 π΄0 π΅ πΆ π· πΈ π΅1 πΆ4 π·3 Example Candidate Frontier (Min Heap) Visited π΄ π΄0 π΅ πΆ π· πΈ π΅1 πΆ4 π·3 πΈ8 Summarized • Create and initialize priority queue (Minimum heap): The queue is initialized with a start node with a cumulative cost of 0. • Node expansion: Expand root node of the heap. For each neighbouring node, if it has not been visited, it is enqueued. If it has been visited, it is skipped. Summarized • Path update: The dequeued node is added to the path. • Goal check: Check if the goal state is met or if the priority queue is empty. If the goal state is met, the algorithm stops, and the path and its costs are returned.