0% found this document useful (0 votes)
13 views22 pages

Lec 2 Artificial Intelligence

The document outlines a lecture on search algorithms, specifically focusing on uninformed search algorithms such as Breadth-First, Depth-First, and Uniform-Cost Search. It discusses the importance of analyzing search algorithms, evaluating their strategies, and provides examples of state space representation. The document also compares different search strategies and suggests when to use each based on the problem characteristics.

Uploaded by

mm7065961
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)
13 views22 pages

Lec 2 Artificial Intelligence

The document outlines a lecture on search algorithms, specifically focusing on uninformed search algorithms such as Breadth-First, Depth-First, and Uniform-Cost Search. It discusses the importance of analyzing search algorithms, evaluating their strategies, and provides examples of state space representation. The document also compares different search strategies and suggests when to use each based on the problem characteristics.

Uploaded by

mm7065961
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/ 22

Computer Engineering Program, MCU

CSE 332
Artificial Intelligence and Intelligent Agents
Lecture #2
Search Algorithms: Uninformed search Algorithms
Instructor:
Dr .Belal Badawy
Belal1_baa@yahoo.com

Spring 2025 1
Outlines

 Introduction to Search Algorithms


 Search Problem Example: Traveling in Romania
 A General Search Algorithm
 Evaluating Search Strategies
 Uninformed search Algorithms
 Breadth-First Algorithm
 Depth-First Algorithm
 Uniform-Cost Search

2
Introduction to Search Algorithms
 To successfully design and implement search algorithms, a programmer
must be able to analyze and predict their behavior.
 Many questions needed to be answered by the algorithm these include:
1. Is the problem solver guaranteed to find a solution?
2. Will the problem solver always terminate, or can it become caught in
an infinite loop?
3. When a solution is found, is it guaranteed to be optimal?
4. What is the complexity of the search process in terms of time usage?
Space search?
5. How can the interpreter be designed to most effectively utilize a
3
representation language?
3
Introduction to Search Algorithms
 State Space Search
The theory of state space search is our primary tool for answering these
questions, by representing a problem as state space graph, we can use
graph theory to analyze the structure and complexity of both the problem
and procedures used to solve it.
 Graph Theory
A graph consists of a set of a nodes and a set of arcs or links connecting
pairs of nodes. The domain of state space search, the nodes are
interpreted to be stated in problem solving process, and the arcs are
taken to be transitions between states.
4
 Graph theory is our best tool for reasoning about the structure of
4
objects and relations.
Introduction to Search Algorithms
• Graph Theory

Nodes={a,b,c,d,e}
Arcs={(a,b), (a,c), (b,a),(b,c),(b,e),(d,e),(c,b),(c,d)(d,c),(d,e),(e,b),(e,d)}

5
Introduction to Search Algorithms
• A state space is represented by four tuple [N,A,S,G], where:-
 N is a set of nodes or states of the graph. These correspond to the
states in a problem –solving process.
 A is the set of arcs between the nodes. A successor function (with
actions, costs)
 S a nonempty subset of N , contains the start state of the problem.
 G a nonempty subset of N contains the goal state of the problem.

A solution path:- is a sequence of actions (a plan) which transforms the start


state to a goal state
6

6
Search Problem Example: Traveling in Romania
 State space: Cities
 Successor function: Roads: Go
to adjacent city with cost =
distance
 Start state: Arad
 Goal test: Is state == Bucharest?
Solution?

7
Search Algorithm
During search, a node can be in one of the three categories:
 Not generated yet (has not been made explicit yet)
 OPEN: generated but not expanded
 CLOSED: expanded
Search strategies differ mainly on how to select an OPEN node for
expansion at each step of search
• OPEN list
– initialization: {S}
– node insertion/removal depends on specific search strategy
• CLOSED list
– initialization: {} 8

– organized by back-pointers 8
A General Search Algorithm

open := {S}; closed :={};


repeat
n := select(open); /* select one node from open for expansion */
if n is a goal
then exit with success; /* delayed goal testing */
expand(n)
/* generate all children of n
put these newly generated nodes in open (check duplicates)
put n in closed (check duplicates) */
until open = {};
exit with failure

9
Evaluating Search Strategies
• Completeness
– Guarantees finding a solution whenever one exists
• Time complexity
– How long (worst or average case) 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 number of nodes in memory.
• Optimality
– If a solution is found, is it guaranteed to be an optimal one? That is,
is it the one with minimum cost?
 Time and Space Complexity measure by:
– b: maximum branching factor of the search tree
10
– d: depth of the least –cost solution
– m: maximum depth of the state space 10
Search Strategies
• Uninformed search strategies
– Also known as “blind search,” use only the information available in
the problem definition.
– Uninformed search methods: Breadth-first, depth-first, depth-
limited, uniform-cost, depth-first iterative deepening, bidirectional
• Informed search strategies
– Also known as “heuristic search,” informed search strategies use
information about the domain to (try to) (usually) head in the
general direction of the goal node(s)
– Informed search methods: Hill climbing, best-first, greedy search,
beam search, A, A*
• Adversarial Search (Game Theory)

11

11
Uninformed search Algorithms: Breadth-First Algorithm
• Algorithm outline:
– Always select from the OPEN the node with 1
the smallest depth for expansion, and put all
newly generated nodes into OPEN 1 b
– OPEN is organized as FIFO (first-in, first-
out) list, i.e., a queue. 2 b^2
– Terminate if a node selected for expansion is
a goal
• Properties
– Complete if b is finite
– Time Complexity: 1 + b + b^2 + ... + b^d =
O(b^d)
b^d
– Optimal if all operators have the same cost.
Otherwise, not optimal but finds solution with
shortest path length (shallowest solution).
– Exponential time and space complexity,
O(b^d) nodes , where
d is the depth of the solution and 12
b is the branching factor (number of children)
12
at each node
Uninformed search Algorithms: Breadth-First Algorithm
Open (FIFO) queue Closed X
[A] [] A
[BCD] [A] B
[CDEF] [AB] C
[DEFGH] [ABC] D
[EFGHIJ] [ABCD] E
[FGHIJKL] [ABCDE] F
[GHIJKLM] [ABCDEF] G
Suppose start is A and goal is N
[HIJKLMN] [ABCDEFG] H
[IJKLMNOP] [ABCDEFGH] I Path: [ABCDEFGHIJKLMN]

[JKLMNOPQ] [ABCDEFGHI] J
[KLMNOPQR] [ABCDEFGHIJ] K
[LMNOPQRS] [ABCDEFGHIJK] L 13
[MNOPQRST] [ABCDEFGHIJKL] M
13
[NOPQRST] [ABCDEFGHIJKLM] N
Uninformed search Algorithms: Depth-First Algorithm
• Algorithm outline:
– Always select from the OPEN the node with the greatest
depth for expansion, and put all newly generated nodes into
OPEN
– OPEN is organized as LIFO (last-in, first-out) list. Stack
– Terminate if a node selected for expansion is a goal
• Properties
−May not terminate without a "depth bound," i.e., cutting off search
below a fixed depth D (How to determine the depth bound?)
−Not complete (with or without cycle detection, and with or without a
cutoff depth)
−Exponential time, O(b^d), but only linear space, O(bd), required
• Can find deep solutions quickly if lucky
• When search hits a deadend, can only back up one level at a time
even if the "problem" occurs because of a bad operator choice
near the top of the tree.
14

14
Uninformed search Algorithms: Depth-First Algorithm
Open (LIFO) stack Closed X

[A] [] A
[BCD] [A] B
[EFCD] [AB] E
[KLFCD] [ABE] K
[SLFCD] [ABEK] S
[LFCD] [ABEKS] L
[TFCD] [ABEKSL] T Suppose start is A and goal is N
[FCD] [ABEKSLT]
Path: [ABEKSLTMCGN]
[LMCD] [ABEKSLT] DELET L M
[CD] [ABEKSLTM] C
[GHD] [ABEKSLTMC] G
15
[NHD] [ABEKSLTMCG] N
15
Comparing Between BFS & DFS
BFS DFS
starts traversal from the root node starts the traversal from the root
and visits nodes in a level by level node and visits nodes as far as possible
manner from the root node (i.e., depth wise).
Usually implemented using a queue Usually implemented using a stack
data structure data structure
Generally requires more memory than Generally requires less memory than
DFS. DFS.
Optimal for finding the shortest Not optimal for finding the shortest
Used for finding the shortest path Used for topological sorting, solving
between two nodes, testing if a graph problems that require graph
is bipartite, finding all connected backtracking, detecting cycles in a
components in a graph graph,
finding paths between two nodes

16

16
Uninformed search Algorithms: Uniform-Cost Search

• Use priority queue by path cost( least cost first). Pop the
element with least cost
• Complete (*)
• Optimal (*)
• Optimal depends on the goal test being applied when a node is
removed from the nodes list, not when its parent node is
expanded and the node is first generated
• Exponential time and space complexity, O(bd)

17

17
Uninformed search Algorithms: Uniform-Cost Search
Let the graph be as below with source node being A and destination E.
Solve in alphabetic order

18

18
Uniform-Cost Search Example

19

19
Comparing Search Strategies

Where:
– b: maximum branching factor of the
search tree
– d: depth of the least –cost solution 20
– m: maximum depth of the state space
20
When to use what
• Depth-First Search:
– Many solutions exist
– Know (or have a good estimate of) the depth of solution
• Breadth-First Search:
– Some solutions are known to be shallow
• Uniform-Cost Search:
– Actions have varying costs
– Least cost solution is required
This is the only uninformed search that worries about costs.

http://aispace.org/search/index.shtml

21

21
22

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