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

AI Lecture 3

The document discusses different search algorithms used in artificial intelligence. It describes uninformed search algorithms like breadth-first search (BFS), depth-first search (DFS), and their properties. BFS uses a queue data structure and explores all nodes at each level, while DFS uses a stack and explores nodes to their maximum depth first before backtracking. Examples are given to illustrate how BFS and DFS expand nodes during the search process.

Uploaded by

Hanoee Abd
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)
52 views29 pages

AI Lecture 3

The document discusses different search algorithms used in artificial intelligence. It describes uninformed search algorithms like breadth-first search (BFS), depth-first search (DFS), and their properties. BFS uses a queue data structure and explores all nodes at each level, while DFS uses a stack and explores nodes to their maximum depth first before backtracking. Examples are given to illustrate how BFS and DFS expand nodes during the search process.

Uploaded by

Hanoee Abd
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

Lecture 3

Search Algorithms in Artificial


Intelligence
Search algorithms
Properties of Search Algorithms:
Completeness: Guarantees finding a solution whenever one
exists.

Time complexity: How long does it take to find a solution?


Usually measured in terms of the number of nodes expanded.

Space complexity: How much space is used by the algorithm?


Usually measured in terms of the maximum size of the “nodes”
list during the search.

Optimality: If a solution is found, is it guaranteed to be an


optimal one? That is, is it the one with minimum cost?
Search algorithms
Search algorithms can classified into uninformed
(Blind search) search and informed search
(Heuristic search) algorithms.
Uninformed Search:
The uninformed search does not contain any
domain knowledge such as closeness, the location
of the goal.

Uninformed search is also called blind search. It


examines each node of the tree until it achieves the
goal node.
Uninformed Search:
1. Breadth-first search
2. Depth-first search
3. Uniform-cost search
4. Depth-limited search
5. Iterative deepening search
6. Bidirectional search
Breadth-first search (BFS)
❑ BFS is the most common search strategy for
traversing a tree or graph.

❑ BFS algorithm starts searching from the root node of


the tree and expands all successor node at the
current level before moving to nodes of next level.

❑ BFS implemented using FIFO (First in First Out)


queue data structure.
Breadth-first search (BFS)
Example 1: S is start node and K is goal node. Determine
the path that reach to the goal:

S --> A --> B --> C--> D --> G --> H --> E --> F --> I --> K
Breadth-first search (BFS)
Example 2: Consider 1 be the start state and 7 be the goal
state. Apply BFS to show expanded nodes for each step.

2 3

4 5 6 7

8 9
Breadth-first search (BFS)

2 3 FRINGE = (1)

4 5 6 7

8 9
Breadth-First Strategy

2 3 FRINGE = (2, 3)

4 5 6 7

8 9
Breadth-First Strategy

2 3 FRINGE = (3, 4, 5)

4 5 6 7

8 9
Breadth-First Strategy

2 3 FRINGE = (4, 5, 6, 7)

4 5 6 7

8 9
Breadth-First Strategy

2 3 FRINGE = (5, 6, 7, 8)

4 5 6 7

8 9
Breadth-First Strategy

2 3 FRINGE = (6, 7, 8)

4 5 6 7

8 9
Breadth-First Strategy

2 3 FRINGE = (7, 8, 9)

4 5 6 7

8 9
Breadth-First Strategy

2 3 FRINGE = (8, 9)

4 5 6 7

8 9
Breadth-first search (BFS)
Advantages:
❑ BFS will provide a solution if any solution exists.
❑ If there are more than one solutions for a given
problem, then BFS will provide the minimal solution
which requires the least number of steps.

Disadvantages:
❑ It requires lots of memory since each level of the tree
must be saved into memory to expand the next level.
❑ BFS needs lots of time if the solution is far away from
the root node.
Depth-first search (BFS)
❑ It is called the depth-first search because it starts
from the root node and follows each path to its
greatest depth node before moving to the next
path.

❑ DFS uses a stack data structure for its


implementation. The process of the DFS algorithm is
similar to the BFS algorithm

❑ DFS implemented using LIFO (Last in First Out)


queue data structure.
Depth-first search (BFS)
Example 1: Start searching from root node S to the goal
node G. In the below search tree, will follow the order as:
Root node --> Left node ---> right node.

S --> A --> B --> D--> E --> C --> G


Depth-first search (BFS)
Example 2: Consider A be the start state and C be the goal
state. Apply DFS to show expanded nodes for each step.

Fringe stack:
A

Expanding A,
gives stack:
B
C

So, B next.
Depth-first search (BFS)

Expanding B,
gives stack:
D
E
C

So, D next.
Depth-first search (BFS)

Expanding D,
gives stack:
H
I
E
C

So, H next.
etc.
Depth-first search (BFS)

Stack: ?

So, ? next.
Depth-first search (BFS)

Stack: ?

So, ? next.
Depth-first search (BFS)

Stack: ?

So, ? next.
Depth-first search (BFS)

Stack: ?

So, ? next.
Depth-first search (BFS)

Stack: ?

So, ? next.
Depth-first search (BFS)
Breadth-first search (BFS)
Advantages:
❑ DFS requires very less memory as it only needs to store
a stack of the nodes on the path from root node to the
current node.
❑ It takes less time to reach to the goal node than BFS
algorithm.
Disadvantages:
❑ There is the possibility that many states keep re-
occurring, and there is no guarantee of finding the
solution. DFS algorithm goes for deep down searching
and sometime it may go to the infinite loop.

You might also like