0% found this document useful (0 votes)
6 views39 pages

FAM Unit2 Only IMP

The document discusses search algorithms in artificial intelligence, focusing on problem-solving agents that utilize various search strategies. It outlines key terminologies, properties of search algorithms, and differentiates between uninformed and informed search methods, including specific algorithms like Breadth-First Search, Depth-First Search, and A* Search. Additionally, it addresses local search algorithms and the challenges of non-deterministic actions in real-world scenarios.

Uploaded by

koolavarghese6
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)
6 views39 pages

FAM Unit2 Only IMP

The document discusses search algorithms in artificial intelligence, focusing on problem-solving agents that utilize various search strategies. It outlines key terminologies, properties of search algorithms, and differentiates between uninformed and informed search methods, including specific algorithms like Breadth-First Search, Depth-First Search, and A* Search. Additionally, it addresses local search algorithms and the challenges of non-deterministic actions in real-world scenarios.

Uploaded by

koolavarghese6
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/ 39

UNIT 2

PROBLEM SOLVING
SEARCH ALGORITHM IN AI
? Problem-solving agents:

Search techniques are universal problem-


solving methods.

Rational agents or Problem-solving


agents in AI mostly used these search
strategies

Problem-solving agents are the goal-based


agents
SEARCH ALGORITHM
TERMINOLOGIES:
? Search: Searchingis a step by step procedure to
solve a search-problem in a given search space.
A search problem can have three main factors:
⚫ Search Space: Search space represents a set of
possible solutions, which a system may have.
⚫ Start State: It is a state from where agent
begins the search.
⚫ Goal test: It is a function which observe the
current state and returns whether the goal state is
achieved or not.
? Search tree: A tree representation of search
problem is called Search tree. The root of the
search tree is the root node which is
corresponding to the initial state.
? Actions: It gives the description of all the
available actions to the agent.
PROPERTIES OF SEARCH
ALGORITHMS:

? Completeness: A search algorithm is said to


be complete if it guarantees to return a solution
if at least any solution exists for any random
input.
? Optimality: If a solution found for an algorithm
is guaranteed to be the best solution (lowest
path cost) among all other solutions, then such
a solution for is said to be an optimal solution.
? Time Complexity: Time complexity is a
measure of time for an algorithm to complete
its task.
? Space Complexity: It is the maximum storage
space required at any point during the search,
as the complexity of the problem.
TYPES OF SEARCH ALGORITHMS

? Based on the search problems we can


classify the search algorithms into
uninformed (Blind search) search and
informed search (Heuristic search)
algorithms.
UNINFORMED/BLIND SEARCH:

? The uninformed search does not contain


any domain knowledge such as closeness,
the location of the goal.

? it is also called blind search.

? It examines each node of the tree until it


achieves the goal node.
INFORMED SEARCH
? In an informed search, problem information
is available which can guide the search.

? Informed search strategies can find a


solution more efficiently than an uninformed
search strategy.

? Informed search is also called a Heuristic


search.
BREADTH FIRST SEARCH
ALGORITHM (UNINFORMED)
? As breadth-first search is the process of
traversing each node of the graph,

? a standard BFS algorithm traverses each


vertex of the graph into two parts: 1) Visited
2) Not Visited.

? So, the purpose of the algorithm is to visit


all the vertex
?
DEPTH FIRST SEARCH ALGORITHM DFS
(UNINFORMED)
1. We take a route
2. keep going until we discover a dead end.
3. When touching the dead end, we again
come back and keep coming back till we
see a path we didn't attempt before.
4. Take that new route and repeat steps 1,2,3

? The Depth-First Search is a recursive


algorithm that uses the concept of
backtracking.
?
GENERATE AND TEST
(INFORMED / HEURISTIC SEARCH TECHNIQUES)
? Algorithm: Generate-And-Test

? 1. Generate a possible solution.

? 2. Test to see if this is the expected solution.

? 3. If the solution has been found quit else


go to step 1
? Generate-and-test, like depth-first search

? Solutions can also be generated randomly


but solution is not guaranteed.

? Example – Traveling Salesman Problem


(TSP)
EXAMPLE – TRAVELING SALESMAN
PROBLEM (TSP)

? A salesman has a list of cities


? Traveler needs to visit n cities exactly once.
Know the distance between each pair of
cities.
? Want to know the shortest route that visits
all the cities once.
SEARCH FLOW WITH GENERATE AND
TEST
?
HILL CLIMBING
(INFORMED / HEURISTIC SEARCH TECHNIQUES)

? Hill climbing search algorithm is simply a


loop that continuously moves in the
direction of increasing value.

? It stops when it reaches a “peak” where no


neighbor has higher value.
? Step 1: Evaluate the starting state. If it is a
goal state then stop and return success.

? Step 2: Else, continue with the starting state


as considering it as a current state.

? Step 3: Continue step-4 until a solution is


found i.e. until there are no new states left
to be applied in the current state.
? Step 4:
? I. Select a state that has not been yet
applied as the current state

? II. current state is a goal state, then stop


and return success.

? III. If it is better than the current state, then


make it current state and proceed further.

? IV. If it is not better than the current state,


then continue in the loop until a solution is
found.
? Step 5: Exit.
BEST FIRST SEARCH
(INFORMED / HEURISTIC SEARCH TECHNIQUES)

? The idea of Best First Search is to use an


evaluation function to decide which
adjacent is most promising and then
explore.

? We use a priority queue to store the costs of


nodes that have the lowest evaluation
function value.
We start from source “S” and search for goal “I” using
given costs
? pq initially contains S
⚫ We remove S from pq and process unvisited
neighbors of S to pq.
⚫ pq now contains {A, C, B} (C is put before B
because C has lesser cost)

? We remove A from pq and process unvisited


neighbors of A to pq.
⚫ pq now contains {C, B, E, D}
? We remove C from pq and process unvisited
neighbors of C to pq.
⚫ pq now contains {B, H, E, D}

? We remove B from pq and process unvisited


neighbors of B to pq.
⚫ pq now contains {H, E, D, F, G}
? We remove H from pq.
? Since our goal “I” is a neighbor of H, we
return.
A* SEARCH ALGORITHM

 It is a Informed Search Algorithm.

 It used to find the shortest path between an


initial and a final point.

 A* uses of weighted graphs.

 find the optimal path between two nodes in


a graph.
A* SEARCH ALGORITHM

? In A* search algorithm, we use search


heuristic as well as the cost to reach the
node.
A* SEARCH ALGORITHM
A* SEARCH ALGORITHM

? Solution
LOCAL SEARCH ALGORITHM
 This is a type of optimization algorithm used
to find the best solution.

 Starting with an initial solution and then


making minor adjustments to it.

 A small modification to the current solution


creates a new solution.

 Compares current and new solution. If new


solution is superior, replace it with current
solution and repeat the process.
STEPS OF A LOCAL SEARCH
ALGORITHM:
? Initialization: starts with an initial solution
to the problem (random solution)
? Evaluation: quality of the initial solution is
evaluated
? Neighbourhood search:generates
neighboring solutions by making small
modifications to the current solution
? Selection: Compares current and new
solution and select best solution from them
? Termination: terminate when best solution
found
LOCAL SEARCH ALGORITHM

Example : Travelling salesman problem(TSP)


SEARCHING WITH NON-DETERMINISTIC
ACTIONS

 So far: fully-observable, deterministic worlds.


Agent knows exact state. All actions always
produce one outcome.

 Real world = partially observable, non-


deterministic
Percepts become useful: can tell agent which
action occurred – Goal: not a simple action
sequence, but contingency plan
EXAMPLE: VACUUM WORLD
NON-DETERMINISTIC SEARCH TREES

Start state = 1

One solution:
1. Suck,
2. 2. if(state=5) then [right,suck] ]
NON-DETERMINISM: ACTIONS THAT
FAIL
? Action failure is often a non-deterministic
outcome
– Creates a cycle in the search tree

? If no successful solution (plan) without a cycle:


– May return a solution that contains a cycle
– Represents retrying the action

? Infinite loop in plan execution?


– Depends on environment • Action guaranteed to
succeed eventually?
– In practice: can limit loops • Plan no longer
complete (could fail)

You might also like