0% found this document useful (0 votes)
7 views

Unit 2. Problem Solving Through Search

The document discusses problem solving in Artificial Intelligence (AI) through search algorithms, outlining steps such as defining the problem, analyzing it, identifying solutions, and implementing the optimal one. It categorizes search algorithms into uninformed (e.g., BFS, DFS) and informed (e.g., Greedy Best-First Search, A* Search), highlighting their properties like completeness, optimality, time, and space complexity. The document also details the advantages and disadvantages of various algorithms, emphasizing the importance of heuristics in informed search methods.

Uploaded by

adityayevate07
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)
7 views

Unit 2. Problem Solving Through Search

The document discusses problem solving in Artificial Intelligence (AI) through search algorithms, outlining steps such as defining the problem, analyzing it, identifying solutions, and implementing the optimal one. It categorizes search algorithms into uninformed (e.g., BFS, DFS) and informed (e.g., Greedy Best-First Search, A* Search), highlighting their properties like completeness, optimality, time, and space complexity. The document also details the advantages and disadvantages of various algorithms, emphasizing the importance of heuristics in informed search methods.

Uploaded by

adityayevate07
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/ 7

Unit 2.

Problem Solving through Search


1. Problem Solving in Artificial Intelligence

Artificial Intelligence (AI) solves problems by searching through a problem space to find an optimal
solution. The goal is to reach the desired state from the initial state while following defined rules
and constraints.

Steps in AI Problem Solving

1. Define the Problem – Identify the problem, initial and goal states, and constraints.

2. Analyze the Problem – Determine state space, operators, path cost, and goal test.

3. Identify Possible Solutions – Generate multiple possible solutions.

4. Choose the Optimal Solution – Select the most efficient solution based on evaluation.

5. Implement the Solution – Apply the chosen algorithm and execute it.

Examples of AI Problem Solving

• Pathfinding problems (e.g., GPS navigation, robot movement).

• Game playing (e.g., Chess, Tic-Tac-Toe).

• Scheduling and planning (e.g., Job scheduling, Traffic control).

2. Properties of Search Algorithms

All search algorithms are evaluated based on these four key properties:

1. Completeness

• An algorithm is complete if it guarantees finding a solution whenever one exists.

• Example: BFS is complete, but DFS is not always complete (may get stuck in infinite loops).

2. Optimality

• An algorithm is optimal if it always finds the best solution with the lowest cost.

• Example: BFS and A are optimal*, but DFS is not optimal.

3. Time Complexity

• The time required to find a solution, usually measured in Big-O notation.

• Example: BFS has O(b^d), where b is the branching factor, and d is the depth of the
shallowest solution.

4. Space Complexity

• The memory required to execute the algorithm.

• Example: DFS uses O(bm) (where m is the maximum depth), while BFS uses O(b^d).
3. Types of Search Algorithms

Search algorithms are classified into two categories:

3.1 Uninformed Search (Blind Search)

• No prior knowledge about the goal state.

• Explores the search space systematically without heuristics.

• Examples: BFS, DFS, DLS.

3.2 Informed Search (Heuristic Search)

• Uses domain knowledge (heuristics) to guide the search towards the goal.

• More efficient than uninformed search algorithms.

• Examples: Greedy Best-First Search, A* Search Algorithm.

4. Uninformed Search Algorithms

Uninformed search algorithms do not use additional information about goal proximity and explore
the state space blindly.

4.1 Breadth-First Search (BFS)

Overview

• Explores all nodes at a given depth before moving deeper.

• Uses a First-In-First-Out (FIFO) queue.

• Guaranteed to find the shortest path in an unweighted graph.

Algorithm Steps

1. Initialize a queue with the start node.

2. Dequeue a node, check if it's the goal.

3. Enqueue all its unvisited neighbors.

4. Repeat until the goal is found or the queue is empty.

Example: BFS Traversal of a Graph

Consider the following graph:

/\

B C

/\ \
D E F

If we start from A and the goal is F, the BFS traversal is:


A→B→C→D→E→F

Advantages

✔ Guaranteed to find the shortest path in an unweighted graph.


✔ Complete – It always finds a solution if one exists.

Disadvantages

✘ High space complexity (O(b^d)) – Stores all nodes in memory.


✘ Slow for deep graphs.

4.2 Depth-First Search (DFS)

Overview

• Explores a path as deeply as possible before backtracking.

• Uses a Last-In-First-Out (LIFO) stack.

• Efficient in memory but does not guarantee the shortest path.

Algorithm Steps

1. Push the start node onto the stack.

2. Pop a node, check if it's the goal.

3. Push all its unvisited neighbors onto the stack.

4. Repeat until the goal is found or the stack is empty.

Example: DFS Traversal of a Graph

Consider the same graph as before:

/\

B C

/\ \

D E F

DFS traversal (starting from A) could be:


A→B→D→E→C→F

Advantages

✔ Uses less memory (O(bm)) than BFS.


✔ Good for problems with many solutions (e.g., mazes).
Disadvantages

✘ May get stuck in infinite loops (if cycles exist).


✘ Not guaranteed to find the shortest path.

4.3 Depth-Limited Search (DLS)

Overview

• A variant of DFS with a depth limit to avoid infinite loops.

• If the goal is beyond the depth limit, it fails.

Algorithm Steps

1. Set a depth limit (L).

2. Use DFS to explore up to depth L.

3. If the goal is found, return success.

4. If depth limit is reached without finding the goal, return failure.

Advantages

✔ Reduces memory consumption.


✔ Prevents infinite loops in cyclic graphs.

Disadvantages

✘ May not find a solution if the limit is too low.


✘ Does not guarantee the shortest path.

Informed Search Algorithms (Heuristic Search)

Introduction

Informed search algorithms use heuristic functions to improve search efficiency. Unlike uninformed
search methods, which blindly explore the search space, informed searches estimate the cost to
reach the goal and prioritize promising paths.

A heuristic function (h(n)) provides an estimate of the cost from a given node to the goal state,
guiding the search toward optimal solutions.

Key Features of Informed Search

Uses heuristics (h(n)) to reduce unnecessary exploration.


More efficient than uninformed search in large search spaces.
Can be optimized for different problems (e.g., shortest path, best solution).

Types of Informed Search Algorithms

1. Greedy Best-First Search (GBFS) – Prioritizes nodes that appear closest to the goal.
2. A Search Algorithm* – Uses both actual cost (g(n)) and heuristic cost (h(n)) to find the
optimal path.

1. Greedy Best-First Search (GBFS)

Overview

• This algorithm expands the node that appears to be closest to the goal, based on the
heuristic function h(n).

• It does not consider the cost (g(n)) of reaching a node, only how close it seems to the goal.

• Uses a priority queue to select the node with the lowest heuristic value.

Algorithm Steps

1. Initialize a priority queue with the start node.

2. Expand the node with the lowest heuristic value (h(n)).

3. If the goal is reached, return the path.

4. Otherwise, add unvisited neighbors to the queue.

5. Repeat until the goal is found or the queue is empty.

Example Graph

A (h=10)

/ | \

(3)B (1)C (7)H

/ \ | / \

(6)D (4)E (8)F (2)G

\ /

(1)H (Goal, h=0)

Traversal Path Using GBFS

1. Start at A (h=10)

2. Expand C (h=4) (Lowest heuristic)

3. Expand G (h=2)

4. Expand H (h=0) (Goal Found)

Final Path: A → C → G → H

Advantages of GBFS

✔ Faster than BFS & DFS, as it prioritizes the goal.


✔ Uses less memory compared to uninformed search methods.
Disadvantages of GBFS

✘ Not always optimal—may not find the shortest path.


✘ Can get stuck in local optima—chooses a path that appears best but is suboptimal.

2. A Search Algorithm*

Overview

• Combines Greedy Best-First Search and Uniform Cost Search.

• Evaluates nodes using the function: f(n)=g(n)+h(n)f(n) = g(n) + h(n)f(n)=g(n)+h(n) where:

o g(n) = Cost from the start node to n.

o h(n) = Estimated cost from n to the goal.

• Guaranteed to find the optimal path if the heuristic is admissible (never overestimates cost).

Algorithm Steps

1. Initialize a priority queue with the start node.

2. Expand the node with the lowest f(n).

3. If the goal is reached, return the solution.

4. Otherwise, update g(n), compute f(n), and add neighbors to the queue.

5. Repeat until the goal is found.

Example Graph with Costs (g(n)) and Heuristic (h(n))

/ \

B C

/\ /\

D E F G

\ | /

H - Goal

Path Cost Table

Path g(n) (Actual Cost) h(n) (Heuristic) f(n) = g(n) + h(n)

A→C 1 4 5

A→C→G 1+2=3 2 5

A → C → G → H 3+2=5 0 5

Traversal Path Using A Search*


1. Start at A (f(A) = 10)

2. Expand C (f(C) = 5) (Lowest f(n))

3. Expand G (f(G) = 5)

4. Expand H (f(H) = 5) (Goal Found)

Final Optimal Path: A → C → G → H

Advantages of A Search*

✔ Guaranteed to find the optimal solution if h(n) is admissible.


✔ More efficient than BFS & DFS, as it balances cost and heuristic.

Disadvantages of A Search*

✘ Consumes more memory than Greedy Best-First Search.


✘ Performance depends on the heuristic function.

You might also like