AI Chapter 2
AI Chapter 2
Institute of Technology
University of Gondar
Biomedical Engineering Department
Outlines: -
» Searching
» Types of searching
Informed and uninformed searching
2
Searching
1. Why searching?
Searching
Components
» Problem statement
o Information about what to be done
o Constraints
» Goal State
o The state that represents the solution of the problem.
» Solution Space
o The set of start state, intermediate states and goal state
» Operators
o The action that takes us from one state to another
The Seven Bridges of Kaliningrad
Try it
o See if you can walk through the city by crossing each bridge only once.
» Pay attention to the number of lines (edges) coming out of each circle
and vertices.
8-Puzzle problem solving
Input:
1 2 3
4 5
7 8 6 Goal:
1 2 3
4 5 6
7 8
8-Puzzle problem solving
1 2
Input:
4 5 3
7 8 6
2 possible moves:
1 2 3
1 2
4 5
4 5 3
7 8 6
7 8 6
1 2 3
4 5 6
7 8
Goal
8-Puzzle problem solving
1 2
Input:
4 5 3
7 8 6
1 2 1 2 3
4 5 3 4 5
7 8 6 7 8 6
b=3 b=3
1, L 2, R 5, U 3, D 5, R 6, U
1 2 3
4 5 6
Goal 7 8
Exercise
» Searching
Simple search algorithm
» Time Complexity
o Adjacency Lists
✓ Each node is added to queue once
o Adjacency Matrix
✓ Have to check all entries in matrix
Time and Space Complexity
» Imagine searching a tree with branching factor 8 and depth 10. assume a
node requires just 8 bytes of storage. The BFS might require up to:
o 810 nodes
o 8,000Mbytes
o 8 Gbytes
Time and Space Complexity
» Space Complexity
o Queue to handle unexplored nodes
✓ Worst case: all nodes put on queue (if all are adjacent to first
node) s
Depth-first Search
» Time Complexity
o Adjacency Lists
✓ Each node is marked visited once
✓ Each node is checked for each incoming edge
o Adjacency Matrix
✓ Have to check all entries in matrix
Time and Space Complexity
» Space Complexity
o Stack to handle nodes as they are explored
✓ Worst case: all nodes put on stack (if graph is linear)
Problems of BFS and DFS
» DFS has small space requirements (linear depth) but has major problems
o DFS can run forever in search in spaces with infinite length paths
» BFS guarantees finding the lowest path even in the presence of infinite paths, but it
has problem
1. Consider that a person has never been to the city air port. Its early in the morning and assume
that no other person is awake in the town who can guide him on the way. He has to derive on his
car but doesn’t know the way to airport. Clearly identify the four components of the problem
solving in the above statement, i.e, problem statement, operators, solution space, and goal state.
Try to model the problem in a graphical representation.
Informed Search (Heuristics Guided Search)
» Is a variant of generate-and test in which feedback from the test procedure is used to help
the generator decide which direction to move in search space.
» The test function is augmented with a heuristic function that provides an estimate of how
close a given state is to the goal state.
» Hill climbing is often used when a good heuristic function is available for evaluating
states but when no other useful knowledge is available.
Hill climbing
» Algorithm:
o Evaluate the initial state. If it is also goal state, then return it and quit. Otherwise continue with the initial
state as the current state.
o Loop until a solution is found or until there are no new operators left to be applied in the current state:
✓ Select an operator that has not yet been applied to the current state and apply it to produce a new state
• If it is note a goal state but it is better than the current state, then make it the current state.
• If it is note better than the current state. Then continue to the loop.
Best first search
» Combines the advantages of both DFS and BFS into a single method.
» BFS is good because it does not get branches on dead end paths.
» One way of combining the two is to follow a single path at a time, but switch paths
whenever some competing path looks more promising than the current one does
Assignment 1
» Given the following tree, apply DFS and BFS. Show the state of the data structure Q and the
visited list clearly at every step. S is the initial state and D is the goal state.