0% found this document useful (0 votes)
33 views29 pages

W05 - Introduction To Search in AI

Uploaded by

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

W05 - Introduction To Search in AI

Uploaded by

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

INTRODUCTION TO

SEARCH IN AI
By: SEK SOCHEAT
Lecturer Artificial Intelligence
2023 – 2024
Mobile: 017 879 967 MSIT – AEU
Email: [email protected]
TABLE OF CONTENTS
Visualization and Data Tools

1. Introduction

2. Uninformed Search

3. Informed Search

4. Heuristic Functions

5. Applications
2
1. INTRODUCTION
1. INTRODUCTION

What is Search in AI?

• Search in AI refers to the process of navigating through a problem space to find


a solution.

• Search algorithms are fundamental for problem-solving and decision-making in


AI.

Problem-Solving Techniques:

In artificial intelligence, problems can be solved by using searching algorithms,

4
evolutionary computations, knowledge representations, etc.
1. INTRODUCTION

In general, searching is referred to as finding information one needs.

The process of problem-solving using searching consists of the following steps:

• Define the problem

• Analyze the problem

• Identification of possible solutions

• Choosing the optimal solution

• Implementation
5
1. INTRODUCTION

In general, searching is referred to as finding information one needs.

The process of problem-solving using searching consists of the following steps:

• Define the problem

• Analyze the problem

• Identification of possible solutions

• Choosing the optimal solution

• Implementation
6
2. UNINFORMED SEARCH
2. UNINFORMED SEARCH ALGORITHMS

What is Uniformed Search?

Search strategies that use no domain-specific knowledge beyond the problem definition.

Examples: Breadth-First Search (BFS) and Depth-First Search (DFS).

BFS > The path of traversal is: DFS > The path of traversal is:
A —-> B —-> C —-> D —-> E —-> F A —-> B —-> D —-> E —-> C —-> F

8
2. UNINFORMED SEARCH ALGORITHMS

Breadth-First Search
It is of the most common search strategies. It generally starts from the root node and examines the
neighbor nodes and then moves to the next level. It uses First-in First-out (FIFO) strategy as it gives
the shortest path to achieving the solution.
BFS is used where the given problem is very small and space complexity is not considered.

The path of traversal is: A —-> B —-> C —-> D —-> E —-> F


9
2. UNINFORMED SEARCH ALGORITHMS

Breadth-First Search The path of traversal is:


A —-> B —-> C —-> D —-> E —-> F
Explanation:

1. Graph Representation: The graph is represented as an adjacency


list using a dictionary. Each node is a key, and its value is a list of
adjacent nodes.

2. BFS Function:

• Initialization: We initialize a queue with the start node and a set to


keep track of visited nodes.

• Loop: We process nodes by dequeuing them, checking if they are


the goal node, marking them as visited, and enqueuing their
unvisited neighbors.

3. Example Usage: The BFS function is called with 'A' as the start
node and 'F' as the goal node. The result indicates whether a path exists.

10
2. UNINFORMED SEARCH ALGORITHMS

Depth-First Search
The depth-first search uses Last-in, First-out (LIFO) strategy and hence it can be implemented by using
stack. DFS uses backtracking. That is, it starts from the initial state and explores each path to its greatest
depth before it moves to the next path.

DFS will follow:

Root node —-> Left node —-> Right node

11
The path of traversal is: A —-> B —-> D —-> E —-> C —-> F
2. UNINFORMED SEARCH ALGORITHMS

Depth-First Search
The path of traversal is:
Explanation: A —-> B —-> D —-> E —-> C —-> F
1. Graph Representation: The graph is represented as an adjacency list
using a dictionary. Each node is a key, and its value is a list of adjacent nodes.

2. DFS Function:

• Initialization: The function initializes the visited set if it is not provided.

• Mark as Visited: The start node is marked as visited.

• Check Goal: If the start node is the goal node, the function returns True.

• Recursive Call: The function recurses for all unvisited adjacent nodes. If
any recursive call returns True, the function returns True.

• Return False: If no path is found after exploring all adjacent nodes, the
function returns False.

3. Example Usage: The DFS function is called with 'A' as the start node and
'F' as the goal node. The result indicates whether a path exists.

12
2. INFORMED SEARCH ALGORITHMS
3. INFORMED SEARCH ALGORITHMS

What is Informed Search?

Uses problem-specific knowledge (heuristics) to find solutions more efficiently.

Examples: Greedy Best-First Search and A* Search.

The path of traversal is: The path of traversal is:


14 A —-> C —-> G —-> H A —-> C —-> G —-> H
3. INFORMED SEARCH ALGORITHMS

Greedy Best-First Search

Greedy best-first search uses the properties of both depth-first search and breadth-first search.
Greedy best-first search traverses the node by selecting the path which appears best at the
moment. The closest path is selected by using the heuristic function.

Consider the below:

graph with the heuristic values.

The path of traversal is: A —-> C —-> G —-> H


15
3. INFORMED SEARCH ALGORITHMS

Greedy Best-First Search

The path of traversal is:


16 A —-> C —-> G —-> H
3. INFORMED SEARCH ALGORITHMS

Greedy Best-First Search

Explanation:

1. Graph Representation: The graph is represented as an adjacency list using a dictionary. Each node is a key, and its value is a list of
adjacent nodes.

2. Heuristics: The heuristic values are defined for each node, indicating the estimated cost to reach the goal.

3. GBFS Function:

• Initialization: A priority queue (min-heap) is initialized with the start node and its heuristic value.

• Loop: Nodes are dequeued in order of their heuristic values. If the current node is the goal, the function returns True. Otherwise, it
marks the node as visited and enqueues its unvisited neighbors with their heuristic values.

• Return False: If the loop completes without finding the goal, the function returns False.

4. Example Usage: The GBFS function is called with 'A' as the start node and 'H' as the goal node. The result indicates whether a path
exists.
17
3. INFORMED SEARCH ALGORITHMS

A* Search

A* search algorithm is a combination of both uninform cost search and greedy best-first search
algorithms. It uses the advantages of both with better memory usage. It uses a heuristic function to
find the shortest path. A* search algorithm uses the sum of both the cost and heuristic of the node
to find the best path.

The path of traversal is: A —-> C —-> G —-> H


18
3. INFORMED SEARCH ALGORITHMS

A* Search

The path of traversal is:


A —-> C —-> G —-> H
19
3. INFORMED SEARCH ALGORITHMS

A* Search

Explanation:

1. Graph Representation: The graph is represented as an adjacency list with edge costs.

2. Heuristics: A dictionary is used to store heuristic values for each node. The heuristic values should be designed to estimate the cost
from any node to the goal node.

3. GBFS Function:

• Priority Queue: Uses a priority queue to select the node with the lowest estimated total cost (g(n) + h(n)).

• Cost and Path Tracking: Tracks the cost from the start to each node (g_costs) and the best path to reach each node (came_from).

• Reconstruct Path: When the goal node is reached, reconstructs the path by tracing back from the goal to the start.

4. Example Usage: The A* search function is called with 'A' as the start node and 'H' as the goal node. The result shows the path from
the start to the goal.
20
3. HEURISTIC FUNCTIONS
3. HEURISTIC FUNCTIONS

What is Heuristic Functions?

A heuristic function, often denoted as h(n), is used in informed search algorithms to estimate the
cost to reach the goal from a given node 𝑛𝑛. The quality of the heuristic greatly affects the efficiency
of the search algorithm.
Properties of a Good Heuristic: Example Heuristics:

1. Admissible: A heuristic is admissible if it never overestimates • Manhattan Distance: Often used in


grid-based pathfinding where
the cost to reach the goal.
movements are limited to horizontal and
This ensures the optimality of the A* algorithm.
vertical steps.
2. Consistent (Monotonic): A heuristic is consistent if, for every
• Euclidean Distance: Used when
node 𝑛𝑛 and every successor 𝑛𝑛′ of 𝑛𝑛, the estimated cost of reaching diagonal movements are allowed.
the goal from 𝑛𝑛 is no greater than the cost of getting to 𝑛𝑛′ plus the • Custom Heuristics: Based on domain-
estimated cost from 𝑛𝑛′ to the goal. specific knowledge.
22
3. HEURISTIC FUNCTIONS

A* Search

Example: Pathfinding on a Grid


using Manhattan Distance

Assume we have a (5x5) grid and we


want to find the shortest path from the
top-left corner (A) to the bottom-right
corner (E). The nodes and their
connections are defined in the graph,
and the heuristic is calculated based
on Manhattan distance.

Output:
23
Path from A to T: ['A', 'F', 'K', 'P', 'Q', 'R', 'S', 'T']
3. HEURISTIC FUNCTIONS

A* Search
Explanation:

1. Graph Representation: The grid is represented as an


adjacency list, with each node connected to its adjacent nodes
(up, down, left, right).

2. Manhattan Heuristics: The heuristic values for each node are


calculated based on Manhattan distance, which is the sum of the
absolute differences of their x and y coordinates.

3. A* Search Function:

• Uses a priority queue to select the node with the lowest


estimated total cost.

• Tracks the actual cost to reach each node (g_costs) and the
best path taken (came_from).

• Reconstructs the path from the goal back to the start once the
goal is reached.

Output:
24
Path from A to T: ['A', 'F', 'K', 'P', 'Q', 'R', 'S', 'T']
4. APPLICATIONS
4. APPLICATIONS

Applications of Uninformed Search Algorithms

1. Breadth-First Search (BFS): 2. Depth-First Search (DFS):


• Network Broadcasting: BFS is used to • Maze Solving: DFS is used to find paths
propagate information across networks, through mazes or puzzles.
ensuring all nodes receive the message.
• Topological Sorting: Used in scheduling
• Social Networking: Used to find the
problems, such as determining the order of
shortest path between two users in social
tasks given their dependencies.
networks like Facebook or LinkedIn.
• Game Tree Exploration: Applied in AI
• Web Crawling: Utilized by search engines
to systematically explore and index web for games to explore possible moves and
pages. outcomes.
26
4. APPLICATIONS

Applications of Informed Search Algorithms

1. A* Search Algorithm: 2. Greedy Best-First Search:

• Robotics Path Planning: A* is used in • Puzzle Solving: Used in solving puzzles


autonomous robots to find optimal paths like the sliding puzzle, where the algorithm
avoiding obstacles. prioritizes moves closer to the goal.

• Route Optimization: Applied in route


• Video Games: Applied in game AI for
optimization problems where the nearest
character movement and strategy planning.
node to the goal is prioritized.
• GPS Navigation: Used in GPS systems to
• Medical Diagnosis: Utilized in expert
find the shortest path considering real-time systems for medical diagnosis to prioritize
traffic data. symptoms closest to a known disease.
27
4. APPLICATIONS

Applications of Heuristic Functions

1. Manhattan Distance: 2. Admissible Heuristics:

• Grid-Based Pathfinding: Used in A* • Optimal Pathfinding: Used in search


search for pathfinding in grid-based maps, algorithms to guarantee the shortest path by
common in games and robotics. not overestimating the cost.

• Urban Planning: Applied in urban • AI Planning: Applied in AI planning


planning to estimate the distance between problems to ensure optimality in the
points in a city layout. sequence of actions.

• Logistics and Supply Chain: Utilized in • Machine Learning: Utilized in feature


warehouse navigation and delivery routing selection to guide the search for optimal
to estimate travel distances. feature subsets.
28
Thank You!
If you have any questions, please reach me!

You might also like