0% found this document useful (0 votes)
19 views

AI Chapter 2

This document discusses various search algorithms including uninformed searches like breadth-first search and depth-first search as well as informed searches using heuristics. It provides examples of problems that can be solved using these search algorithms and explores their time and space complexities.

Uploaded by

biruck
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)
19 views

AI Chapter 2

This document discusses various search algorithms including uninformed searches like breadth-first search and depth-first search as well as informed searches using heuristics. It provides examples of problems that can be solved using these search algorithms and explores their time and space complexities.

Uploaded by

biruck
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/ 34

Artificial Intelligence

Institute of Technology
University of Gondar
Biomedical Engineering Department

By Ewunate Assaye (MSc.)


Chapter Two
Problem solving by searching

Outlines: -
» Searching

» Types of searching
Informed and uninformed searching

2
Searching

1. Why searching?
Searching

» Solving problems by exploration of alternatives.


Problem solving by 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

There were seven bridges in Kaliningrad,


o Connecting two big islands surrounded by the Pregolya river and two portions of
main lands divided by the same river.
The Seven Bridges of Kaliningrad

Try it
o See if you can walk through the city by crossing each bridge only once.

o There should not be any uncrossed bridge(s).

o Each bridge must not be crossed more than once.


The Seven Bridges of Kaliningrad

» Visually graphs are a good choice for picturing problems.

» 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

Branching factor, b=2

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

» Let S be the start state


1. Initialize Q with the start node Q =(S) as only entry; set visited = (S)
2. If Q is empty, fail, else pick node X from Q
3. If X is a goal, return X, we have reached the goal
4. Otherwise remove X from the Q
5. Find all the children of node X not in visited
6. Add these to Q, add children of X to the visited
7. Go to step 2
What is a graph?
» A graph is
o a set of vertices V and a set of edges E, comprising an ordered pair G=(V, E).
Uninformed (blind) search

» Breadth first search

» Depth first search


Breadth-First Search

» Choose a starting vertex

» Search all adjacent vertices

» Return to each adjacent vertex in turn and visit all of its


adjacent vertices
Breadth-First Search
Breadth-First Search
Time and Space Complexity

» Time Complexity
o Adjacency Lists
✓ Each node is added to queue once

✓ Each node is checked for each incoming edge

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 ((23)10)*210 = 223 bytes

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

» Choose a starting vertex

» Do a depth-first search on each adjacent vertex

» Dives in to a tree deeper and deeper to find the goal state.


Depth-first Search
Depth-first Search
Time and Space Complexity

» 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

o DFS does not guarantee finding the shallowest goal

» BFS guarantees finding the lowest path even in the presence of infinite paths, but it
has problem

o It requires a great deal of space (exponential in depth)


Problems

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)

1. Do you like hiking (hill climbing)? How do you climb?

2. Do you think an algorithm can solve an integral question?


Hill climbing

» 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.

» Computation of heuristic function can be done with negligible amount of computation.

» 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

✓ Evaluate the new state

• If the goal state, then return it and quit.

• 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.

» DFS is good because it allows a solution to be found without all competing


branches having to be expanded.

» 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

1. Write python algorithm for breadth first, depth first, Hill


climbing and Best first searches

Submit via [email protected] before July 05 2022


Quiz 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.

You might also like