SlideShare a Scribd company logo
3
Most read
4
Most read
16
Most read
Uniform Cost Search for
Optimal Path
AI Lab
School of Computer Engineering
Dr Hitesh Mohapatra
Associate Professor
KIIT University
Assignment 4: Uniform Cost Search for
Optimal Path
• Objective:
• Implement Uniform Cost Search for a weighted graph.
• Problem Statement: Given a weighted graph (e.g., a transportation network with travel costs),
find the minimum-cost path between two nodes.
• Tasks:
1. Represent the graph as an adjacency list.
2. Implement Uniform Cost Search to find the optimal path.
3. Compare it with BFS for unweighted graphs.
Definition
• Uniform Cost Search (UCS) is a popular search algorithm used
in artificial intelligence (AI) for finding the least cost path in a
graph.
• It is a variant of Dijkstra's algorithm and is particularly useful
when all edges of the graph have different weights, and the
goal is to find the path with the minimum total cost from a start
node to a goal node.
Key Concepts of Uniform Cost Search
1.Priority Queue: UCS uses a priority queue to store nodes. The node with
the lowest cumulative cost is expanded first. This ensures that the search
explores the most promising paths first.
2.Path Cost: The cost associated with reaching a particular node from the
start node. UCS calculates the cumulative cost from the start node to the
current node and prioritizes nodes with lower costs.
3.Exploration: UCS explores nodes by expanding the least costly node
first, continuing this process until the goal node is reached. The path to
the goal node is guaranteed to be the least costly one.
4.Termination: The algorithm terminates when the goal node is expanded,
ensuring that the first time the goal node is reached, the path is the
optimal one.
How Does Uniform Cost Search Work?
1.Initialization: UCS starts with the root node. It is added to the priority queue with a
cumulative cost of zero since no steps have been taken yet.
2.Node Expansion: The node with the lowest path cost is removed from the priority
queue. This node is then expanded, and its neighbors are explored.
3.Exploring Neighbors: For each neighbor of the expanded node, the algorithm calculates
the total cost from the start node to the neighbor through the current node. If a neighbor
node is not in the priority queue, it is added to the queue with the calculated cost. If the
neighbor is already in the queue but a lower cost path to this neighbor is found, the cost
is updated in the queue.
4.Goal Check: After expanding a node, the algorithm checks if it has reached the goal
node. If the goal is reached, the algorithm returns the total cost to reach this node and
the path taken.
5.Repetition: This process repeats until the priority queue is empty or the goal is reached.
Algorithm
Implementation with
Python
Step 1: Import Required Libraries
Step 2: Define the Uniform Cost Search
Function
Step 3: Define the Path Reconstruction
Function
Step 4: Define the Visualization Function
Step 5: Define the Graph and Execute UCS
Applications of UCS in AI
Uniform Cost Search is widely applicable in various fields within AI:
1.Pathfinding in Maps: Determining the shortest route between two
locations on a map, considering different costs for different paths.
2.Network Routing: Finding the least-cost route in a communication or
data network.
3.Puzzle Solving: Solving puzzles where each move has a cost associated
with it, such as the sliding tiles puzzle.
4.Resource Allocation: Tasks that involve distributing resources efficiently,
where costs are associated with different allocation strategies.
Advantages of Uniform Cost Search
• Optimality: UCS is guaranteed to find the least cost path to the
goal state if the cost of each step exceeds zero.
• Completeness: This algorithm is complete; it will find a
solution if one exists.
Challenges with UCS
• Space Complexity: The main drawback of UCS is its space
complexity. The priority queue can grow significantly,
especially if many nodes are being expanded.
• Time Complexity: The time it takes to find the least cost path
can be considerable, especially if the state space is large.
Example
Complexity
• 𝐵𝑒𝑠𝑡 𝐶𝑎𝑠𝑒 𝐶𝑜𝑚𝑝𝑙𝑒𝑥𝑖𝑡𝑦 = 𝑂(𝑏𝑑
)
• 𝑊𝑜𝑟𝑠𝑡 𝐶𝑎𝑠𝑒 𝐶𝑜𝑚𝑝𝑙𝑒𝑥𝑖𝑡𝑦 = 𝑂(𝑏𝑐∗/𝜖)
Where ,
• Branching Factor (b): The average number of successors per state.
• Depth of the Shallowest Goal Node (d): The depth at which the first goal state is found.
• Maximum Path Cost 𝐶∗
The cost of the optimal solution path.
• Where 𝜖 is the smallest step cost greater than zero
Conclusion
• Uniform Cost Search is a powerful algorithm in AI for situations
where paths have different costs and the goal is to minimize
the total cost.
• Its application across various domains showcases its versatility
and effectiveness.
• However, understanding its computational requirements is
crucial for practical implementations, especially in scenarios
with large data sets or limited computational resources
https://github.com/hm18818/AI-with-
Python/blob/main/Uniform%20Cost%20Search%2
0(UCS)%20in%20AI

More Related Content

PPTX
Interview of an entrepreneur
PDF
المخدرات الرقمية
PDF
Informed search
PPTX
Agentic-AI-The-Next-Wave-of-Intelligence.pptx
PPTX
Circuit Switching
PPT
Logic&proof
PPT
Expert systems
PPTX
Depth first search [dfs]
Interview of an entrepreneur
المخدرات الرقمية
Informed search
Agentic-AI-The-Next-Wave-of-Intelligence.pptx
Circuit Switching
Logic&proof
Expert systems
Depth first search [dfs]

What's hot (20)

PPTX
Ppt 3 - IOT logic design
PPTX
Neuro-fuzzy systems
PPTX
Data cube computation
PDF
Kevin Knight, Elaine Rich, B. Nair - Artificial Intelligence (2010, Tata McGr...
PPT
Hill climbing
PPTX
Bayesian Belief Network and its Applications.pptx
PPTX
lazy learners and other classication methods
PPTX
Problem solving in Artificial Intelligence.pptx
PPTX
Soft computing
PPTX
VANET in Mobile Computing
PDF
CS8791 Cloud Computing - Question Bank
PPTX
Inductive bias
PPSX
Fuzzy expert system
PDF
I. Alpha-Beta Pruning in ai
PPTX
Structure of agents
PDF
Agreement Protocols, distributed File Systems, Distributed Shared Memory
PDF
A* Search Algorithm
PPT
WSN IN IOT
PPTX
Computer Network Technology | Dynamic Host Configuration Protocol
PPTX
Congestion control
Ppt 3 - IOT logic design
Neuro-fuzzy systems
Data cube computation
Kevin Knight, Elaine Rich, B. Nair - Artificial Intelligence (2010, Tata McGr...
Hill climbing
Bayesian Belief Network and its Applications.pptx
lazy learners and other classication methods
Problem solving in Artificial Intelligence.pptx
Soft computing
VANET in Mobile Computing
CS8791 Cloud Computing - Question Bank
Inductive bias
Fuzzy expert system
I. Alpha-Beta Pruning in ai
Structure of agents
Agreement Protocols, distributed File Systems, Distributed Shared Memory
A* Search Algorithm
WSN IN IOT
Computer Network Technology | Dynamic Host Configuration Protocol
Congestion control
Ad

Similar to Uniform-Cost Search Algorithm in the AI Environment (20)

PPTX
unit 2 ai artificial intelligence 1.pptx
PPTX
Search in Algorithm in artificial intelligence
PPTX
A star algorithm with Pseudcode AI.pptx
PPTX
AI(Module1).pptx
PPTX
AI_Lec2.pptx dive in to ai hahahahahahah
PPTX
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPTX
uninformed search part 2.pptx
PDF
Presentation on the artificial intelligenc
PDF
What is A * Search? What is Heuristic Search? What is Tree search Algorithm?
PDF
Search problems in Artificial Intelligence
PPTX
Searching is the universal technique of problem solving in Artificial Intelli...
PPTX
Example of iterative deepening search & bidirectional search
PDF
CSA 3702 machine learning module 3
PDF
Path Finding Solutions For Grid Based Graph
PDF
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PDF
Comparison of various heuristic
PDF
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
PPTX
Introduction to ai and algorithms required to that
PPTX
Chapter 3.pptx
PPTX
Lecture 08 uninformed search techniques
unit 2 ai artificial intelligence 1.pptx
Search in Algorithm in artificial intelligence
A star algorithm with Pseudcode AI.pptx
AI(Module1).pptx
AI_Lec2.pptx dive in to ai hahahahahahah
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
uninformed search part 2.pptx
Presentation on the artificial intelligenc
What is A * Search? What is Heuristic Search? What is Tree search Algorithm?
Search problems in Artificial Intelligence
Searching is the universal technique of problem solving in Artificial Intelli...
Example of iterative deepening search & bidirectional search
CSA 3702 machine learning module 3
Path Finding Solutions For Grid Based Graph
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
Comparison of various heuristic
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
Introduction to ai and algorithms required to that
Chapter 3.pptx
Lecture 08 uninformed search techniques
Ad

More from Hitesh Mohapatra (20)

PDF
Introduction to Edge and Fog Computing.pdf
PDF
Amazon Web Services (AWS) : Fundamentals
PDF
Resource Cluster and Multi-Device Broker.pdf
PDF
Failover System in Cloud Computing System
PDF
Resource Replication & Automated Scaling Listener
PDF
Storage Device & Usage Monitor in Cloud Computing.pdf
PDF
Networking in Cloud Computing Environment
PDF
Logical Network Perimeter in Cloud Computing
PPT
Software Product Quality - Part 1 Presentation
PDF
Multitenancy in cloud computing architecture
PDF
Server Consolidation in Cloud Computing Environment
PDF
Web Services / Technology in Cloud Computing
PDF
Resource replication in cloud computing.
PDF
Software Measurement and Metrics (Quantified Attribute)
PDF
Software project management is an art and discipline of planning and supervis...
PDF
Software project management is an art and discipline of planning and supervis...
PDF
The life cycle of a virtual machine (VM) provisioning process
PDF
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
PDF
Traditional Data Center vs. Virtualization – Differences and Benefits
PDF
Inter-Cloud Architecture refers to the design and organization of cloud services
Introduction to Edge and Fog Computing.pdf
Amazon Web Services (AWS) : Fundamentals
Resource Cluster and Multi-Device Broker.pdf
Failover System in Cloud Computing System
Resource Replication & Automated Scaling Listener
Storage Device & Usage Monitor in Cloud Computing.pdf
Networking in Cloud Computing Environment
Logical Network Perimeter in Cloud Computing
Software Product Quality - Part 1 Presentation
Multitenancy in cloud computing architecture
Server Consolidation in Cloud Computing Environment
Web Services / Technology in Cloud Computing
Resource replication in cloud computing.
Software Measurement and Metrics (Quantified Attribute)
Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...
The life cycle of a virtual machine (VM) provisioning process
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
Traditional Data Center vs. Virtualization – Differences and Benefits
Inter-Cloud Architecture refers to the design and organization of cloud services

Recently uploaded (20)

PPT
Project quality management in manufacturing
PPTX
web development for engineering and engineering
PDF
Digital Logic Computer Design lecture notes
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Welding lecture in detail for understanding
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
PPT on Performance Review to get promotions
PPTX
Geodesy 1.pptx...............................................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
CH1 Production IntroductoryConcepts.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
UNIT 4 Total Quality Management .pptx
Project quality management in manufacturing
web development for engineering and engineering
Digital Logic Computer Design lecture notes
R24 SURVEYING LAB MANUAL for civil enggi
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Lecture Notes Electrical Wiring System Components
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Welding lecture in detail for understanding
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Mechanical Engineering MATERIALS Selection
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT on Performance Review to get promotions
Geodesy 1.pptx...............................................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CH1 Production IntroductoryConcepts.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Automation-in-Manufacturing-Chapter-Introduction.pdf
UNIT 4 Total Quality Management .pptx

Uniform-Cost Search Algorithm in the AI Environment

  • 1. Uniform Cost Search for Optimal Path AI Lab School of Computer Engineering Dr Hitesh Mohapatra Associate Professor KIIT University
  • 2. Assignment 4: Uniform Cost Search for Optimal Path • Objective: • Implement Uniform Cost Search for a weighted graph. • Problem Statement: Given a weighted graph (e.g., a transportation network with travel costs), find the minimum-cost path between two nodes. • Tasks: 1. Represent the graph as an adjacency list. 2. Implement Uniform Cost Search to find the optimal path. 3. Compare it with BFS for unweighted graphs.
  • 3. Definition • Uniform Cost Search (UCS) is a popular search algorithm used in artificial intelligence (AI) for finding the least cost path in a graph. • It is a variant of Dijkstra's algorithm and is particularly useful when all edges of the graph have different weights, and the goal is to find the path with the minimum total cost from a start node to a goal node.
  • 4. Key Concepts of Uniform Cost Search 1.Priority Queue: UCS uses a priority queue to store nodes. The node with the lowest cumulative cost is expanded first. This ensures that the search explores the most promising paths first. 2.Path Cost: The cost associated with reaching a particular node from the start node. UCS calculates the cumulative cost from the start node to the current node and prioritizes nodes with lower costs. 3.Exploration: UCS explores nodes by expanding the least costly node first, continuing this process until the goal node is reached. The path to the goal node is guaranteed to be the least costly one. 4.Termination: The algorithm terminates when the goal node is expanded, ensuring that the first time the goal node is reached, the path is the optimal one.
  • 5. How Does Uniform Cost Search Work? 1.Initialization: UCS starts with the root node. It is added to the priority queue with a cumulative cost of zero since no steps have been taken yet. 2.Node Expansion: The node with the lowest path cost is removed from the priority queue. This node is then expanded, and its neighbors are explored. 3.Exploring Neighbors: For each neighbor of the expanded node, the algorithm calculates the total cost from the start node to the neighbor through the current node. If a neighbor node is not in the priority queue, it is added to the queue with the calculated cost. If the neighbor is already in the queue but a lower cost path to this neighbor is found, the cost is updated in the queue. 4.Goal Check: After expanding a node, the algorithm checks if it has reached the goal node. If the goal is reached, the algorithm returns the total cost to reach this node and the path taken. 5.Repetition: This process repeats until the priority queue is empty or the goal is reached.
  • 8. Step 1: Import Required Libraries
  • 9. Step 2: Define the Uniform Cost Search Function
  • 10. Step 3: Define the Path Reconstruction Function
  • 11. Step 4: Define the Visualization Function
  • 12. Step 5: Define the Graph and Execute UCS
  • 13. Applications of UCS in AI Uniform Cost Search is widely applicable in various fields within AI: 1.Pathfinding in Maps: Determining the shortest route between two locations on a map, considering different costs for different paths. 2.Network Routing: Finding the least-cost route in a communication or data network. 3.Puzzle Solving: Solving puzzles where each move has a cost associated with it, such as the sliding tiles puzzle. 4.Resource Allocation: Tasks that involve distributing resources efficiently, where costs are associated with different allocation strategies.
  • 14. Advantages of Uniform Cost Search • Optimality: UCS is guaranteed to find the least cost path to the goal state if the cost of each step exceeds zero. • Completeness: This algorithm is complete; it will find a solution if one exists.
  • 15. Challenges with UCS • Space Complexity: The main drawback of UCS is its space complexity. The priority queue can grow significantly, especially if many nodes are being expanded. • Time Complexity: The time it takes to find the least cost path can be considerable, especially if the state space is large.
  • 17. Complexity • 𝐵𝑒𝑠𝑡 𝐶𝑎𝑠𝑒 𝐶𝑜𝑚𝑝𝑙𝑒𝑥𝑖𝑡𝑦 = 𝑂(𝑏𝑑 ) • 𝑊𝑜𝑟𝑠𝑡 𝐶𝑎𝑠𝑒 𝐶𝑜𝑚𝑝𝑙𝑒𝑥𝑖𝑡𝑦 = 𝑂(𝑏𝑐∗/𝜖) Where , • Branching Factor (b): The average number of successors per state. • Depth of the Shallowest Goal Node (d): The depth at which the first goal state is found. • Maximum Path Cost 𝐶∗ The cost of the optimal solution path. • Where 𝜖 is the smallest step cost greater than zero
  • 18. Conclusion • Uniform Cost Search is a powerful algorithm in AI for situations where paths have different costs and the goal is to minimize the total cost. • Its application across various domains showcases its versatility and effectiveness. • However, understanding its computational requirements is crucial for practical implementations, especially in scenarios with large data sets or limited computational resources