0% found this document useful (0 votes)
16 views8 pages

Ai Assignment 2 Modi

The document describes the steps of the uniform cost search algorithm to find the shortest path from Oradea to Craiova in a graphical map. It provides the detailed steps taken by the algorithm, what is in memory at each step, estimates the time and space complexity, and confirms that uniform cost search provides a complete solution for this problem.

Uploaded by

Rehan Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Ai Assignment 2 Modi

The document describes the steps of the uniform cost search algorithm to find the shortest path from Oradea to Craiova in a graphical map. It provides the detailed steps taken by the algorithm, what is in memory at each step, estimates the time and space complexity, and confirms that uniform cost search provides a complete solution for this problem.

Uploaded by

Rehan Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMSATS UNIVERSITY ABBOTABAD DEPARTMENT OF

ELECTRICAL AND COMPUTER ENGINEERING

Submitted By:

NAME Registration
Muhammad Rehan FA21 -BCE-002

Artificial Intelligence
Assignment #: 2

Date: 20-oct-2023
Course Instructor: Dr. Imran Shahzad
Question :
j

Find out the shortest path from Oradea to Craiova in the given graphical map using uniform cost
search algorithm? In the response to this question, you should include:

Part a:
Complete details and steps of the algorithm.
Uniform Cost Search:
The Uniform Cost Search (UCS) algorithm is a variant of Dijkstra's algorithm that is used for
finding the lowest-cost path between a given initial node and all other nodes in a weighted graph.
UCS is a systematic search algorithm that explores paths by expanding the nodes with the lowest
cumulative cost from the initial node.

Steps for the UCS algorithm:


1. Initialize the priority queue (usually implemented using a min-heap or a priority queue)
with the start node and its cost, which is initially 0.
2. Create an empty set to keep track of visited nodes.
3. While the priority queue is not empty, do the following steps:
 Pop the node with the minimum cost from the priority queue. This node will be the
current node.
 If the current node is the goal node, the algorithm terminates, and the path is found.
 Otherwise, if the current node has not been visited, mark it as visited and expand it
by examining its neighboring nodes.
 For each neighboring node, compute the cost to reach that node from the start node
by adding the cost of the current node to the cost of the edge connecting the current
node to the neighboring node.
 If the neighboring node has not been visited or if the newly computed cost is less
than the previous cost to reach that node, update the cost and add the neighboring
node to the priority queue.
4. If the priority queue becomes empty and the goal node is not reached, then there is no path
from the start node to the goal node

Part b:

Order of steps/actions taken by the algorithm, and what is in the memory at each step/action.

Step 1:

Explored List Frontier List


{Oradea,0}

Step 2:

Explored List Frontier List


{Oradea,0}
Oradea (not goal) { Zerind:71,Sibiu:151} expand

Step 3:

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind(not goal) {Arad:146,Sibiu:151}expand
Step 4:

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad(not goal) {Sibiu:151,Sibiu:286,Timisoara:264}expand

Step 5:

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu(not goal) {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}expand

Step 6

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}
Rimnicu(not goal) {Fagaras:250,Sibiu:286,Timisoara:264,Craiova:377,Pitesti:328}expand
Step 7 :

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}

Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}
Rimnicu {Fagaras:250,Sibiu:286,Timisoara:264,Craiova:377,Pitesti:328}
Fagaras(not goal) {Timisoara:264,Sibiu:286,Pitesti:328,Craiova:377,Bucharest:461}expand

Step 8:

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}
Rimnicu {Fagaras:250,Sibiu:286,Timisoara:264,Craiova:377,Pitesti:328}
Fagaras {Timisoara:264,Sibiu:286,Pitesti:328,Craiova:377,Bucharest:461}
Timisoara(not goal) {Sibiu:286,Lugoj:375, Pitesti:328,Bucharest:461,Craiova:377} expand
Step 9:

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}
Rimnicu {Fagaras:250,Sibiu:286,Timisoara:264,Craiova:377,Pitesti:328}
Fagaras {Timisoara:264,Sibiu:286,Pitesti:328,Craiova:377,Bucharest:461}
Timisoara {Sibiu:286,Lugoj:375, Pitesti:328,Bucharest:461,Craiova:377}
Sibiu(not goal) {Pitesti:328,Lugoj:375,Craiova:377,Bucharest:461} expand

Step 10:

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}
Rimnicu {Fagaras:250,Sibiu:286,Timisoara:264,Craiova:377,Pitesti:328}
Fagaras {Timisoara:264,Sibiu:286,Pitesti:328,Craiova:377,Bucharest:461}
Timisoara {Sibiu:286,Lugoj:375, Pitesti:328,Bucharest:461,Craiova:377}
Sibiu {Pitesti:328,Lugoj:375,Craiova:377,Bucharest:461}
Piteshi(not goal) {Lugoj:375,Bucharest:429, Craiova:377,Bucharest:461} expand
Step 11:

Explored List Frontier List


{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}
Rimnicu {Fagaras:250,Sibiu:286,Timisoara:264,Craiova:377,Pitesti:328}
Fagaras {Timisoara:264,Sibiu:286,Pitesti:328,Craiova:377,Bucharest:461}
Timisoara {Sibiu:286,Lugoj:375, Pitesti:328,Bucharest:461,Craiova:377}
Sibiu {Pitesti:328,Lugoj:375,Craiova:377,Bucharest:461}

Piteshi {Lugoj:375,Bucharest:429, Craiova:377,Bucharest:461}


Lugoj(not goal) {Craiova:377,Bucharest:429,Bucharest:461,Mehadia:445} expand

Step 12:
Explored List Frontier List
{Oradea,0}
Oradea { Zerind:71,Sibiu:151}
Zerind {Arad:146,Sibiu:151}
Arad {Sibiu:151,Sibiu:286,Timisoara:264}
Sibiu {Rimnicu:231,Fagaras:250,Timisoara:264,Sibiu:286}
Rimnicu {Fagaras:250,Sibiu:286,Timisoara:264,Craiova:377,Pitesti:328}
Fagaras {Timisoara:264,Sibiu:286,Pitesti:328,Craiova:377,Bucharest:461}
Timisoara {Sibiu:286,Lugoj:375, Pitesti:328,Bucharest:461,Craiova:377}
Sibiu {Pitesti:328,Lugoj:375,Craiova:377,Bucharest:461}
Piteshi {Lugoj:375,Bucharest:429, Craiova:377,Bucharest:461}
Lugoj {Craiova:377,Bucharest:429,Bucharest:461,Mehadia:445}
Craiova(Goal) {Bucharest:429,Bucharest:461,Mehadia:445} no expand

Craiova is a goal node so the path that will be :

Path: 'Oradea'  'Sibiu'  'Rimnicu'  'Craiova'


Part c:
Estimate the space and time complexity for the given state Space.

Time Complexity:
C*= 377
£=70
So,
T.C = O(b^(1+C*/£)
= O(3^(1+377/70)
= O(1114

Space Complexity:
C*= 377
£=70
So,
S.C = O(b^(1+C*/£)
= O(3^(1+377/70)
= O(1114)

Part d:
Describe whether uniform cost search provide complete solution or not. Give at least one
example to justify your claim.

Answer :
Uniform cost search is considered complete if two conditions are fulfilled:
1. All step costs are non-negative. (Cost > =0)
2. There exists a finite positive limit on the step costs.
When these prerequisites are satisfied, the uniform cost search algorithm is guaranteed to
identify the optimal solution.
In the context of the Romania map, the step costs adhere to non-negative values, and
there exists a finite positive upper bound on them. Consequently, the uniform cost search
method is assured to deliver a comprehensive solution for determining the shortest path
from Oradea to Craiova, ensuring the discovery of the path with the minimum cost.

You might also like