0% found this document useful (0 votes)
24 views12 pages

Solving Problems by Searching: Universidad Cooperativa de Colombia

Here is Python code for implementing depth-first search to solve the 8-puzzle problem: ```python from collections import deque initial_state = [1, 2, 3, 4, 5, 6, 7, 8, 0] goal_state = [1, 2, 3, 4, 5, 6, 7, 8, 0] def get_successors(state): successors = [] empty_index = state.index(0) if empty_index > 0: successor = list(state) successor[empty_index], successor[empty_index-1] = successor[empty_index-1], successor[empty_index

Uploaded by

Laura Gomez
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)
24 views12 pages

Solving Problems by Searching: Universidad Cooperativa de Colombia

Here is Python code for implementing depth-first search to solve the 8-puzzle problem: ```python from collections import deque initial_state = [1, 2, 3, 4, 5, 6, 7, 8, 0] goal_state = [1, 2, 3, 4, 5, 6, 7, 8, 0] def get_successors(state): successors = [] empty_index = state.index(0) if empty_index > 0: successor = list(state) successor[empty_index], successor[empty_index-1] = successor[empty_index-1], successor[empty_index

Uploaded by

Laura Gomez
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/ 12

Solving Problems

by Searching

Universidad Cooperativa de Colombia


Ingeniería de Sistemas

Reference:
1. S. Russell and P. Norvig. Artificial Intelligence: A Modern Approach. Chapter 3
Schedule
• Uninformed Search
– Breadth-first search
– Uniform-cost search
– Depth-first search
– Depth-limit search
– Iterative deepening search
– Bidirectional search
Uninformed Search
• Also called blinded search
• No knowledge about whether one non-goal state is
“more promising” than another

• Six search strategies to be covered


– Breadth-first search
– Uniform-cost search
3
– Depth-first search
– Depth-limit search
– Iterative deepening search
– Bidirectional search
Breadth-First Search (BFS)
• Select the shallowest unexpended node in the search
tree for expansion
• Implementation
– Fringe is a FIFO queue, i.e., new successors go at end

• Complete (if b is finite)


• Optimal (if unit step costs were adopted)
– The shallowest goal is not always the optimal one ?
• Time complexity: O(bd+1) suppose that the solution is
the right most one at depth d
– b+b2+b3+…. +bd+b(bd-1)= O(bd+1)
• Space complexity: O(bd+1) Number of nodes generated

– Keep every node in memory


– 1+b+b2+b3+…. +bd+b(bd-1)= O(bd+1)
Goal test → Generating Successors (by the successor function) → Choosing one to Expand AI - Berlin Chen 27
Breadth-First Search (cont.)

For the same level/depth, nodes are expanded in a left-to-right manner. AI - Berlin Chen 28
Breadth-First Search (cont.)
• Impractical for most cases
• Can be implemented with beam pruning
– Completeness and Optimality will not be held

– Memory is a bigger problem than execution time


Uniform-Cost Search Dijkstra 1959

• Similar to breadth first search but the node with lowest


path cost expanded instead

• Implementation
– Fringe is a queue ordered by path cost

• Complete and optimal if the path cost of each step was


positive (and greater than a small positive constant ε)
– Or it will get suck in an infinite loop (e.g. NonOp action) with
zero-cost action leading back to the same state

• Time and space complexity: O( ⎡C / ε ⎤)


b *

– C* is the cost of the optimal solution


Depth-First Search (DFS)
• Select the deepest unexpended node in the current
fringe of the search tree for expansion
• Implementation
– Fringe is a LIFO queue, i.e., new successors go at front
• Neither complete nor optimal
• Time complexity is O(bm)
– m is the maximal depth of any path in the state space
• Space complexity is O(bm)→ bm+1
– Linear space !
Depth-First Search (cont.)

9
Depth-First Search (cont.)

• Would make a wrong choice and get stuck going down


infinitely
Depth-First Search (cont.)

Up Left

repeated states
Down Up Left

11
Down Left
Write Python code for

8-Puzzle

You might also like