Chapter 4 - Searching The Knowledge Space I

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

Department of Computer Sciences

College of Computers & Information Technology

501481-3 Summer 2022

Artificial Intelligence
Chapter 4: Searching the
Knowledge Space – Uninformed
Search
1
Introduction
• When solving a problem, it’s convenient to
think about the solution space in terms of a
number of actions that we can take, and the
new state of the environment as we perform
those actions
• The space problem is represented by graph
• To find a solution is equivalent to searching a
path in graph
Introduction
• While solving the problem, some paths may
lead to dead-ends while others lead to
solutions
• there may also be multiple solutions, some
better than others.
• The problem of search is to find a sequence of
operators that transit from the start to goal
state.
• That sequence of operators is the solution.
Types of Search in AI
• We have two types of search:
• Uninformed or blind search and,
• Informed or heuristic search.

In this chapter we are going to study different


types of uninformed or blind search.

Artificial Intelligence 4
07:15 PM
Evaluating Search Strategies
• Completeness: Is the strategy guaranteed to find a
solution if one exists?
• Optimality: Does the solution have low cost or the
minimal cost?
• Complexity: What is the search cost associated
with the time and memory required to find a
solution?
• Time complexity: Time taken (number of nodes expanded) (worst or
average case) to find a solution.
• Space complexity: Space used by the algorithm measured in terms of
the maximum size of fringe
Evaluating Search Strategies
• Big-O is used to compare the algorithms.
– Defines asymptotic upper bound given:
• Depth of tree (d).
• Average number of branches (b) (branch factor).
Uninformed Search
• The uninformed search methods offer a
variety of techniques for graph search, each
with its own advantages and disadvantages

• Uniformed search, also called blind search and


naïve search, is a class of general purpose
search algorithms that operate in a brute force
way.
Outline of Search Algorithm
1. Initialize: Open ={s}
2. Fail: If Open={} then return FAIL.
3. Select: select a state n from Open.
4. Terminate:
If n ∈ G then terminate with success.
5. Expand:
Generate the successor of n using the
operators O and insert them in Open.
6. Loop: Go to step 2.

Artificial Intelligence 8
07:15 PM
Improvement on the Search Algorithm
1. Initialize: Open ={s} closed={}
2. Fail: If Open={} then return FAIL.
3. Select: select a state n from Open.
Save n in closed
4. Terminate:
If n ∈ G then terminate with success.
5. Expand:
Generate the successor of n using the
operators O. For each successor m, insert
them in Open if m ∉ (Open ∪ Closed).
6. Loop: Go to step 2.

Artificial Intelligence 9
07:15 PM
Depth First Search (DFS)
Depth First Search (DFS)
• Search each branch to its greatest depth.
• Treat Open list as stack (LIFO)

• Nodes that are visited will not be pushed in the stack.


• Nodes that are already in the stack will not be pushed in the
stack
stack 1 Push 1 1
s
1 432 Pop 1. Push 4,3,2 2

2 3 4 436 Pop 2. Push 6 3


43 Pop 6. 4
6 5 7
45 Pop 3. Push 5 5
9 8 47 Pop 5. Push 7 6

Path is {1,2,3,5,7} 4 Pop 7 Goal found 7


11

Artificial Intelligence
07:15 PM
Depth First Search
• Branch factor: b (Average number of branches ),
• goal depth: d, tree depth: m
• Space complexity: O(bm) (linear).
• Time complexity: O(bm)=1+b+b2+b3+…+bm (exponential).

m
Depth First Search
• Assume: b=10, space: 100 bytes/node,
• Time: 1000 nodes/seconds.

Depth Nodes Time Memory


0 1 1 ms 100 Bytes
2 21 21 ms 2100 Bytes
4 41 41 ms 4100 Bytes
6 61 61 ms 6100 Bytes
8 81 81 ms 8100 Bytes
Comments on Depth First Search
• DFS is complete If no cycles in graph

• DFS is not complete if cycles exist.


– If there are cycles in the graph, DFS may get
“stuck” in one of them. Solve by checking visited
nodes.

• Disadvantages:
– Can get stuck into wrong path, too deep.
Artificial Intelligence 14
07:15 PM
Comments on Depth First Search
• DFS is not optimal.

• It can “stumble” on longer


solution paths before it
gets to shorter ones.
• E.g., goal nodes: red boxes
Comments on Depth First Search
• Space Complexity
- for every node in the path
currently explored, DFS
maintains a path to its
unexplored siblings in the
search tree
- Alternative paths that
DFS needs to explore
- The longest possible path
is m, with a maximum of
b-1 alterative paths per
node
Comments on Depth First Search
• Time Complexity:
- In the worst case,
must examine
every node in the
tree
• E.g., single goal
node -> red box
Breadth First Search
Breadth First Search
• Search the closest nodes to the root first before descending to
the next level.
• Treat Open list as queue (FIFO).

• Nodes that are already in the queue will not be en-queued.


• Nodes that are visited will not be en-queued.
Queue
s 1 enQ 1. 1
1
2 deQ 1. enQ 2,3,4 234
2 3 4 3 deQ 2. enQ 6 346
4 deQ 3. enQ 5 465
6 5 7
5 deQ 4. enQ 7 657

9 8 6 deQ 6 57
7 deQ 5 7
Path is {1,2,3,4,7} 8 deQ 7, goal found
Artificial Intelligence 19
07:15 PM
Complexity of Breadth First Search
• Branch factor = b. Depth = d.
• Space complexity: O(bd).
• Time complexity: 1+b+b2+b3+..bd = O(bd)

Artificial Intelligence 20
07:15 PM
Complexity of Breadth First Search
• Assume: b=10, 100 bytes/nodes,
1000nodes/second.
Depth Nodes Time Space
0 1 1 ms 100 bytes
2 1+b+b2=111 111 ms 11 kilobytes
4 11,111 11 seconds 1 megabytes.
6 ≅ 106 ≅ 17 minutes ≅ 100 megabytes
8 ≅ 108 ≅ 28 hours ≅ 11 gigabytes
10 ≅ 1010 ≅ 128 days ≅ 1 terabytes
12 ≅ 1012 ≅ 35 years ≅ 111 terabytes

Artificial Intelligence 21
07:15 PM
Comments on Breadth First Search
• BFS is complete
(The strategy guaranteed to find a solution if one
exists)

• BFS is optimal
(it can find the best goal, in terms of shortest
path to the node)

Artificial Intelligence 22
07:15 PM
Comparison of DFS and BFS

Complete Optimal Time Space

DFS N N O(bm) O(bm)


No cycles: Y

BFS Y Y O(bm) O(bm)


Comparison of DFS and BFS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy