0% found this document useful (0 votes)
301 views38 pages

4 Search - V3

The document discusses different search strategies and algorithms used in artificial intelligence, including: 1) Blind search algorithms like breadth-first search and depth-first search that systematically search the state space without any heuristics. Breadth-first search explores the shallowest nodes first, while depth-first search explores the deepest nodes in the search tree first. 2) Heuristic search algorithms like hill climbing, best-first search, and A* that use heuristics to guide the search towards more promising areas of the state space. A* uses an evaluation function that combines path cost and heuristic estimation to find optimal solutions. 3) Heuristic search techniques for games including minimax and alpha-beta pruning that aim to

Uploaded by

Ay Sy
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)
301 views38 pages

4 Search - V3

The document discusses different search strategies and algorithms used in artificial intelligence, including: 1) Blind search algorithms like breadth-first search and depth-first search that systematically search the state space without any heuristics. Breadth-first search explores the shallowest nodes first, while depth-first search explores the deepest nodes in the search tree first. 2) Heuristic search algorithms like hill climbing, best-first search, and A* that use heuristics to guide the search towards more promising areas of the state space. A* uses an evaluation function that combines path cost and heuristic estimation to find optimal solutions. 3) Heuristic search techniques for games including minimax and alpha-beta pruning that aim to

Uploaded by

Ay Sy
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/ 38

MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

CHAPTER 4
SEARCH

STRUCTURES AND STRATEGIES FOR STATE SPACE SEARCH


(SSS) ___________________________________________________ 1
BACKTRACKING SEARCH ALGORITHM ______________________ 4
BLIND SEARCH __________________________________________ 6
BREADTH –FIRST SEARCH (BFS) __________________________ 6
DEPTH –FIRST SEARCH (DFS) ____________________________ 8
HEURISTIC SEARCH _____________________________________ 10
HILL CLIMBING ________________________________________ 10
BEST FIRST SEARCH ___________________________________ 13
A* ALGORITHM ________________________________________ 15
HEURISTIC SEARCH IN GAMES ____________________________ 18
MINIMAX ______________________________________________ 18
ALPHA-BETA (-ß) PRUNING ____________________________ 19
PRACTICE MAKES PERFECT ______________________________ 20

4:0
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

3 SEARCH

STRUCTURES AND STRATEGIES FOR STATE SPACE


SEARCH (SSS)

Graph Theory
▪ Graph consists of a set of:
o Nodes – a state.
o Arcs – connect pairs of nodes – a transitions between states.
o Ex. Chess – node represent a state of chessboard. The arc represents legal
moves from one state to another.
▪ If a directed arc connects Nj and Nk, the Nj is called the parent of Nk and Nk is called the
child of Nj.
▪ If (Nj,Ni) then Nk and Ni are called siblings.
▪ A rooted graph has a unique node Ns from which all paths originate.
▪ A tip or leaf is a node that has no children.
▪ On a path in a rooted graph, a state is said to be an ancestor of all states positioned
after it (to its right) and a descendant of all states before it (to its left).
▪ A tree is a graph in which there is a unique path between every pair of nodes. Each
node in a rooted tree has u unique parent.

State Space Representation of Problems

▪ A state space is represented by a found-tuple [N,A,S,G]


▪ N is a set of nodes or states of graph. These correspond to the states in a problem-
solving process.
▪ A is the set of arcs between the nodes. These correspond to the steps in a problem-
solving process.
▪ S, a nonempty subset of N, contains the start state(s) of the problem.
▪ G, a nonempty subset of N, contains the goal state(s) of the problem. The states in G are
describes using either:
o A measurable property of the state encounters in the search.
o A property of the path developed in the search.
▪ A solution path is a path through this graph from a node in S to a node in G.

4:1
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Example: Traveling Salesman Problem

A 100
B
75

125 12
5
50

100
125 75
E

50 C
D 100
Starting at A, find the shortest path through all the cities, visiting each city exactly once and
returning to A. The figure below shows the search tree for the given TSP.
A

B C D E

C D E

D E C E

E D E C

A A A

Searching is defined as looking for something whose presence is suspected. In AI,


something is referred to as a goal. The whole process of searching is usually presented as a
number of steps that describe a connection between the point at which the search starts and
the goal.

4:2
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Question

Draw a complete search tree showing the state space of the above map from
the city A to city Z.

Solution A

X M Y
A A

G M
A A

M G Y Z S
A X G M M
M A A A
A

4:3
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

BACKTRACKING SEARCH ALGORITHM


Backtracking is a technique for systematically trying all paths through a state space (Luger,
2005). Search begins at the start state and pursues a path until it reaches a goal or a “dead
end”. If it reaches a goal, it returns the solution path and quits. If it reaches a dead end, it
backtracks to the most recent node in the path having unexamined siblings and continues
down one of those branches.

The backtracking algorithm uses 4 lists:


▪ CS – the current state.
▪ SL – the state list – lists the states in the current path being tried. If a goal is found, SL
contains the ordered list of states on the solution path.
▪ NSL – the new state list, contains nodes awaiting evaluation – not yet been generated.
▪ DE – dead ends, lists states whose descendants have failed to contain a goal node. If
these states are encountered again, they were immediately eliminated from
consideration.
PROCEDURE Backtracking() Notes (initially):
Queue SL  Start
Queue NSL  Start CS: dotted arrow.
Queue DE
Node CS  Start %initialize
SL: contain CS with
while NSL not empty
if CS = goal previous SL that
return SL has/have not dead yet.
end if

if CS has no children (excluding nodes in DE, SL, NSL) NSL: contain child of
while SL is not empty and CS = the first element
of SL previous CS with
add CS to DE previous NSL.
remove first element from SL
remove first element from NSL
CS  first element in NSL
end while
DE: node will not dead
add CS to SL until node has no child
end
else
or node’s child has
place children of CS into NSL (except nodes dead.
already in DE, SL, NSL)
CS  first element of NSL
add CS to SL
end
end while

CS SL NSL DE
A
A [A] [A] []
B [B,A] [B,C,A] []
D [D,B,A] [D,E,B,C,A] [] B C
E [E,B,A] [E,B,C,A] [D]
C [C,A] [C,A] [B,E,D]
F [F,C,A] [F,C,A] [B,E,D]
D E F
[] [] [] [A,C,F,B,E,D]

4:4
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Question Perform backtracking onto the following tree to the goal G.

C F B

Q W E R T Y S D G

Solution CS SL NSL DE

4:5
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Searching can be divided into 2 types:


i. Blind Search
ii. Heuristic Search

BLIND SEARCH
According to Callan, Blind Search algorithms perform a methodical exhaustive search. There
is no information used in guiding the search but it uses a fixed strategy for generating states
and testing for the goal. There are 2 simple algorithms that falls in Blind Search category:

i. Breadth-First Search
ii. Depth-First Search

BREADTH –FIRST SEARCH (BFS)


BFS starts at the root and explores the whole of one level in the tree before moving on to the
next level. Each node within a level is visited in a left to right order. Below is a simple tree
for an abstract problem where Q is taken as a goal state.

B C

D E F G H

I J K L M N

O P Q

The algorithm for implementing BFS makes use of two structures, which are: -

i. opened→ a queue that holds a record of which nodes to visit next


ii. closed→a queue that holds records each node that has been visited.

4:6
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Below is the algorithm for implementing BFS.

PROCEDURE BreadthFirstSearch(Tree tree, Node root, Goal goal, List closed

Node current
Queue opened

Add root to opened

while opened is not empty


current first node on opened
remove first node from opened
if current=goal
add current to closed
return true
end if

for each child node C of current


add C to opened, at the end of the list
end for
add current to closed
end while

Based on the previous algorithm, the queue in BFS is based on First-In-First-Out (FIFO)
data structure, where the next element to be removed will be the one that was placed
earliest onto the queue.

Evaluated node Opened Closed


[A] []
A [B,C] [A]
B [C,D,E] [A,B]
C [D,E,F,G,H] [A,B,C]
D [E,F,G,H,I] [A,B,C,D]
E [F,G,H,I,J,K] [A,B,C,D,E]
F

4:7
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

DEPTH –FIRST SEARCH (DFS)


DFS is similar to BFS, but it goes deep into the tree following the descendants of a node
before returning to explore siblings. The order of search for DFS is as the following example,
where Q is considered as a goal state for this tree.

B C

D E F G H

I J K L M N

Goal Found
O P Q

Same as BFS, DFS also use two structures in implementing the algorithm, which are:

i. opened → a queue that holds a record of which nodes to visit next


ii. closed→a queue that holds records each node that has been visited.

Below is the algorithm for implementing DFS.

PROCEDURE DepthFirstSearch(Tree tree, Node root, Goal goal, List closed

Node current
Queue opened

Add root to opened

while opened is not empty


current first node on opened
remove first node from opened
if current=goal
add current to closed
return true
end if

for each child node C of current


add C to opened, in front of the list
end for
add current to closed
end while

4:8
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Compared to BFS, the queue for DFS is based on Last-In-First-Out (LIFO) data structure,
where the next element to be removed will be the one that was placed earliest onto the
queue. Below is the list on how the queue of states opened and the closed list develop
during execution of DFS algorithm on the given tree.

Evaluated node Opened Closed


[A] []
A [B,C] [A]
B [D,E,C] [B,A]
D [I, E,C] [D,B,A]
I

4:9
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

HEURISTIC SEARCH
Heuristic is a method that guaranteed to find a good solution in reasonable time, but
sometimes it might not find the best solution. According to Callan, a heuristic function is a
rule that will return a value for a node that indicates how promising the search will be if it
explores paths that emerge from that node.

A heuristic function can be called to evaluate how promising the search will be if the paths
leading from that node are explored. The nodes in opened can be ordered according to the
values that the function returns for each node and this will depend on the way the problem is
expressed.

Here, the value is treated by a function as a cost and look to minimize the cost. Therefore,
problems are usually expressed so that nodes with lower values take precedence over those
with high value.
There are 3 types of heuristic search that will be covered in this chapter, which are:-
• Hill Climbing
• Best First Search
• A* Algorithm

HILL CLIMBING
Hill climbing looks like to maximize cost as opposed to minimizing it. Hill climbing search is a
heuristic search that always seeks to improve on the existing state with the next move,
where it never makes a move to a less desirable state. If the search reaches the local ridge,
it will get stuck because all successive moves take the search down before being able to
move back up (improving).

The idea is do not keep the big list of state around, but just keep track of the one state you
are considering and the path that got you there from the initial state. This strategy expands
the current state of the search and evaluates its children. Here, the best child is selected for
further expansion. This will lead to the goal and continue from there. Hill climbing comes
from the idea that you are trying to find the top and you got direction that is up from wherever
you are. This strategy often works but since it only uses information, it can be fooled. Here,
only the best child is maintained. If the node has no children, the searching process is
terminated, and no turning back (no backtracking). The goal is detected only if the minimum
cost function is found, where the cost function for child is more than the parent’s cost
function.

The algorithm for Hill Climbing is as follows:

i. Evaluate the initial state if it is goal state quit otherwise current state is initial
state.
ii. Select a new operator for this state and generate a new state.
iii. Evaluate the new state
a. if it is closer to goal state than current state makes it current state
b. if it is no better ignore
iv. If the current state is goal state or no new operators available, quit. Otherwise
repeat from 2.

4:10
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

For example:

Based on the search tree below, perform hill climbing. Given H0 is goal.

A∞

B10 C11

D8 E13 G∞ H0

K14 L15

Evaluated node Opened Closed

[A∞] []
A∞ [B10, C11] [A∞]
B10 [D8, E13] [B10, A∞]
D8 [K14, L15] [D8,B10, A∞]
Search terminated and failed.

***Here, since in the question H0 is given as a goal, the searching process is terminated and
failed.

Following are several drawbacks of hill climbing technique:

1. Local Maxima

The major problem of hill climbing is local maxima. If it reaches to a state that has better
solution than its children, the algorithm stops. If the state is not the goal, but just a local
maximum, the algorithm may fail to find the best solution.

Next figure is an example of the local maxima


X
dilemma. Suppose exploring this search space,
we want to maximize state values.

3 4 2

4 2 3 3

3 5 4 3 2 3

4:11
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

2. Plateau

Another problem with hill climbing is plateau. This occurs when it gets to a “flat” part of a
search space. It usually happens when the heuristics are all very close to each other. This
kind of flatness can cause the algorithm to cease progress and wander aimlessly.

Question Perform hill climbing onto the following tree to the goal K.

1 3 7

S D F

9 7 5 4 1 2

G H J K L Q

5
4

W E

8
1
2

R T Y

Solution Evaluated
Node Opened Closed

4:12
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

BEST FIRST SEARCH

Best-First Search is a search that orders the search on the basis of node preference (Callan,
2003). It is a combination of Depth-First Search and Breadth-First Search. The search can
be implemented based on the following algorithm:
PROCEDURE BestFirstSearch(Tree tree, Node root, Goal goal, List closed)

node current
<DS> opened

add root to opened

while opened is not empty


currentfirst node on opened
remove first node from opened
if current=goal
add current to closed
return true
end if

for each child node C of current


if C is not on closed and not on opened
add C to opened
sort all nodes in C according to heuristic function
end if

end for
add current to closed

end while

Given is a tree that has been populated with costs to illustrated heuristic search

8 A

6 B 7 C

5 D 2 E 3 F 8 G 6 H

11 I 9 J 7 K 3 L 2 M 8 N

10 O 2 P 0 Q

4:13
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

A priority queue will order its elements according to some precedence. Best First Search can
be implemented so that every time a child is placed on opened all of the nodes are ordered
so that the lowest cost node is always the next node to be removed. The heuristic function
determines the cost and therefore the ordering of nodes. Below is the order of node visits for
the previous tree as determined by a Best First Search.

Evaluated node Opened Closed


[A8]
A8 [B6,C7] [A8]
B6 [E2,D5,C7] [B6, A8]
E2 [D5, C7, K7, J9] [E2, B6, A8]
D5 [C7, K7, J9, I11] [D5, E2, B6, A8]
C7

Question The following state-space search is a hypothetical solution for a game tree,
where A is the start state and L is the goal state.

B:5 C:6

D:8 E:7 F:10 G:5 H:3 I:4

J:6 K:4 L:2 M:1

Show all the steps involved for each open and closed list while performing
hill climbing search.

Evaluated
Solution Node Opened Closed

4:14
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

A* ALGORITHM

In A* Algorithm, a child node is generated by applying an operator to the parent node. As


nodes represent states, the branch connecting two nodes denotes a state transformation. A
path in a search tree therefore represents a succession of state transitions. A cost can
associated with the operator for expanding the node. The cost of a path can then be
evaluated by summing the cost of 1 for each operation along the path. Here, the cost of path
to the node n is the depth of node n. If cost is based on the depth of a node the breadth first
search is guaranteed to find the cheapest path to the goal.

A heuristic function that combines g(n) and h(n) is:

f(n) = g(n) + h(n)

where g(n) measures the actual length of the path from any state n to the start state, and
h(n) is a heuristic estimate of the distance from state n to goal. In general, h(n)describes
how close node n to the goal. h(n) always relies upon some heuristic information available
from the problem domain.

The function f(n) provides an estimated cost of the cheapest solution through node n. It
sums the cost of the path from the start node to node n, with cheapest path estimate from n
to the goal. If the function h(n) never overestimates the cost of reaching the goal, then h(n)
is said to be admissible. If best-first search uses f(n) as the heuristic function and h(n) is
admissible, the search is known as A* algorithm.

Consider a family vacation where the Dad, Mom and the two kids are all crammed into a car.
After about 5 minutes, the kids start asking “How much father ‘til we get there?” To sate the
children’s curiosity for a few minutes, the dad will make a rough guess. “Another 300 miles. It
will be a while, so why don’t you take a nap?”. If the family had already driven 100 miles at
that point, that would represent g(n), the total distance traveled so far. The estimate of 300
miles would be h(n) – the guess on how much farther it would be. So, for f(n) would be 100
+ 300 = 400 miles.

Terms.

Admissibility
When a search algorithm is guaranteed to find the minimal path to the goal, whenever the
path exists, then the search algorithm is called admissible.

Informedness
For two heuristics h1 and h2, if h1(n) ≤ h2(n) for all states n in the search space, heuristic h1
is said to be more informed than h2.

Monotonicity
A heuristic function h is monotone if:
1. For all states ni and nj, where nj is a descendent of ni, h(ni) - h(nj) ≤ cost(ni,nj), where
cost(ni,nj) is the actual cost (in number of moves) of going from state ni to nj.
2. The heuristic evaluation of the goal state is zero, or h(goal) = 0.

4:15
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

EXERCISE & SOLUTION

Ex1 A pipeline is to be built that will link six cities. The cost (in millions) of
constructing each potential link depends on distance and terrain and is
shown in the weighted graph below. Use A* algorithm to find the
minimum path to build the pipeline from A to D.

A 1.5 B

h(n)
1.6
0.8
A 3.3
2.5
C 1.8 B 1.7
A
1.9 C 1.7
1.7 A
D 0
2.9 2.2
E 1.1
1.1
F 2.3
E D
1.2

Solution f(A) = 0 + 3.3


A
= 3.3

f(B) = 1.5 + 1.7 f(C) = 1.6 + 1.7


= 3.2 f(E) = 2.5 + 1.1 f(F) = 1.9 + 2.3
= 3.3 = 3.6
B C E = 4.2 F

C D

f(C) = 2.3 + 1.7 f(D) = 3.3 + 0


= 4.0 = 3.3

4:16
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Ex2 An ant has to navigate its way from square A3 to square E3. It cannot enter the
dark squares as they represent walls.
A B C D E

1
2

3 Goal
4
5

Given that, the cost to move is the number of boxes it goes through. And the
h(n) are given in the following table.
A B C D E

1 6 5 4 3 2

2 6 4 1
3 5 3 0
4 5 4 3 2 1

5 5 4 3 2

Solution

4:17
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

HEURISTIC SEARCH IN GAMES


Another important application of using heuristic search is in game playing. Two person
games are more complicated, as the reaction of the opponent is always unpredictable.

Two search techniques have been developed to cater games problem, minimax and alpha
beta pruning. Both techniques are suitable for two player games.

MINIMAX
In Minimax search algorithm, the opponents in the game are referred as MIN and MAX. The
significance of referring with these names are as follows:

MAX: represents the player that trying to maximize his advantage in order to win the
game.

MIN: represents the player who attempts to minimize MAX’s score. Always move to a
state that is worst for MAX.

The minimax search propagates the values up the graph, through successive parents,
according to these rules:
If the parent state is MAX, give it the maximum value of its children.
If the parent state is MIN, give it the minimum values of its children.

Exercise Consider the following game tree. Find the best move for the MAX player using
the minimax procedure.
A

2 3 5 9 0 7 4 2 1 5 6

4:18
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

ALPHA-BETA (-ß) PRUNING


The idea of alpha-beta search is simpler than minimax. Rather than searching the entire
space, alpha-beta search proceeds in a depth-first style. Two values, alpha and beta are
introduced during the search.

The algorithm of alpha-beta search is as follows:

/*
alpha is the best score for max along the path to state
beta is the best score for min along the path to state

returns VALUE of best operator


need additional code to return operator
*/
int minimaxAB(state, player, depth, alpha, beta)
if (depth == limit or state is terminal)
return the static evaluation of state
if (player is min)
until all successors, s, are examined or alpha > beta
val=minimaxAB(s, max, depth+1, alpha, beta)
if (val < beta)
beta = val
return beta
if (player is max)
until all successors, s, are examined or alpha > beta
val=minimaxAB(s, min, depth+1, alpha, beta)
if (val > alpha)
alpha = val
return alpha

Exercise Consider the following game tree. Find the best move for the MAX player using
the alpha-beta search.

2 3 5 9 0 7 4 2 1 5 6

4:19
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

PRACTICE MAKES PERFECT

1. Draw a complete state space search for the following map, to move from A to F.

F E A C

4:20
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

2. Consider the following graph.

B:1 C:5 D:8 E:6

F:5 G:6 H:3 I:8 J:6 K:3 L:5

M:8 N:4 O:2 P:5 Q:9 R:5 S:3 Goal

T:8 U:6

V:5 X:1

a) Perform Best First Search onto the given graph to move from A to S.

4:21
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

b) Perform Depth First Search onto the given graph to move from A to S.

c) Perform Hill-Climbing onto the given graph to move from A to S.

d) Perform Breadth First Search onto the given graph to move from A to S.

4:22
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

3. Consider the following graph.

B:5 C:6

D:8 E:7 F:10 G:5 H:3 I:4

J:6 K:4 L:2 M:1

a) Perform Breadth First Search onto the given graph to move from A to M.

b) Perform Depth First Search onto the given graph to move from A to M.

4:23
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

c) Perform Hill-Climbing onto the given graph to move from A to M.

d) Perform Best First Search onto the given graph to move from A to M.

4:24
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

4.
A
36

B
61
31

32 80 L
D C
52
31
E F 102

43 112
G K
20 122
32
H M
40 36

I
45
J
Using the A* algorithm work out a route from town A to town M. Use the following cost
functions.
➢ G(n) = The cost of each move as the distance between each town (shown on map).
➢ H(n) = The straight line distance between any town and town M. These distances are
given in the table below.
Provide the search tree for your solution and indicate the order in which you expanded the
nodes. Finally, state the route you would take and the cost of that route.
Straight Line Distance to M
A 223 E 165 I 100 M 0
B 222 F 136 J 60
C 166 G 122 K 32
D 192 H 111 L 102

5. Consider the following map (not drawn to scale).

A
42
48
B
20
23

D C 40 L
42
29
E F 20

10 42
G K
20 40
41
H M
10
32
I
23 J

4:25
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Using the A* algorithm work out a route from town A to town M. Use the following cost
functions.
➢ G(n) = The cost of each move as the distance between each town (shown on map).
➢ H(n) = The straight line distance between any town and town M. These distances are
given in the table below.
Provide the search tree for your solution, showing the order in which the nodes were
expanded and cost at each node. You should not re-visit states previously visited. Finally,
state the route you would take and the cost of that route.
Straight Line Distance to M
A 51 E 42 I 50 M 0
B 50 F 14 J 32
C 32 G 33 K 41
D 28 H 43 L 56

6. Consider the following map (not drawn to scale)

73
64
104
C
B 89

D E

83 64
F 40 G

31 35
89

H 84
I J
36 20
35 28
53
K L M 113

63 50 80

O N
41

72
P Q
65
65
R

4:26
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Using the A* algorithm work out a route from A to R, using the following cost functions
g(n) = the distance between each town (shown on map)
h(n) = the straight line distance between any town and town R. These distances are given in
the table below
Straight Line Distance to R
A 240
B 186
C 182
D 163
E 170
F 150
G 165
H 139
I 120
J 130
K 122
L 104
M 100
N 77
O 72
P 65
Q 65
R 0

In your answer provide the following.

i) The search tree that is produced, showing the cost function at each node
(10)
ii) State the order in which the nodes were expanded
(2)
iii) State the route that is taken, and give the total cost
(1)

7. Consider the following map (not drawn to scale)


A 40 B
11.18
C 10 D 22.36 10
5
20 E F G 10 H
10 5
I J
14.14 10 10
5

K 20 20 M
L

Using the A* algorithm work out a route from town A to town M. Use the following cost
functions.
➢ G(n) = The cost of each move as the distance between each town (shown on map).
➢ H(n) = The straight line distance between any town and town M. These distances are
given in the table below.

4:27
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Straight Line Distance to M


A 44.72 E 31.62 I 11.18 M 0.00
B 20.00 F 22.36 J 5.00
C 33.54 G 14.14 K 40.00
D 25.00 H 10.00 L 20.00
a) Provide the search tree for your solution, showing the order in which the nodes were
expanded and the cost at each node. You should not re-visit a town that you have
just come from.
State the route you would take and the cost of that route.

(14 marks)
b) Assume the straight line distance table was replaced by the following table.

Straight Line Distance to M


A 90.00 E 6.00 I 23.00 M 0.00
B 10.00 F 54.00 J 34.00
C 40.00 G 19.00 K 27.00
D 18.00 H 16.00 L 108.00

What route would now be returned by the A* algorithm and what would the cost of that route
be?
(6 marks)

8. Consider the 8-puzzle problem below.

Given the initial state as below;


2 8 3
1 6 4
7 5

and the goal state as; 1 2 3


8 4
7 6 5

Using A* algorithm, complete a figure below. Given:


f(n) = g(n) + h(n), where:
g(n) = distance of n from start, and
h(n) = quantity of marbles which is dislocated.

4:28
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

Start

g(n) = 0 2 8 3 State A
h(n) = 4
1 6 4 f(n) = 4
7 5

g(n) = 1

2 8 3 State B State C 2 8 3 State D 2 8 3


1 6 4 h(n) = 5 h(n) = 3 1 4 h(n) = 5 1 6 4
f(n) = 6 f(n) = 4 f(n) = 6
7 5 7 6 5 7 5

4:29
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

9. Apply left-to-right / right-to-left α-β pruning on the tree and show the path which would
lead to a win for minimum / maximum (refer to respective questions).

i) left-to-right - Minimizing

2 7 1 8

ii) left-to-right - Maximizing

2 7 1 8

4:30
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

iii) right-to-left - Minimizing

2 7 1 8

iv) right-to-left - Maximizing

2 7 1 8

4:31
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

10. Apply left-to-right / right-to-left α-β pruning on the tree and show the path which would
lead to a win for minimum / maximum (refer to respective questions).

i) left-to-right - Minimizing

3 12 8 2 4 6 14 5 2

ii) left-to-right - Maximizing

3 12 8 2 4 6 14 5 2

4:32
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

iii) right-to-left - Maximizing

3 12 8 2 4 6 14 5 2

iv) right-to-left - Minimizing

3 12 8 2 4 6 14 5 2

4:33
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

11. Apply a left-to-right α-β pruning on the tree which would lead to a win for maximum. If
there is any cutoff, indicate where it occurs and state the intermediate value for each
path.

2 5 5 7 8

7 6 0 7 7 8 5 4

12. Apply a left-to-right α-β pruning on the tree which would lead to a win for maximum. If
there is any cutoff, indicate where it occurs and state the intermediate value for each
path

1 3 -2 2 4 -1 1 2 -1 4 7 3 6 -1 -1 1 2 4 5 -2 7

4:34
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

i) Consider the game tree given below and answer the questions below. Apply a right-to-
left α-β pruning on the tree which would lead to a win for minimum. If there is any
cutoff, indicate where it occurs and state the intermediate value for each path

1 3 -2 2 4 -1 1 2 -1 4 7 3 6 -1 -1 1 2 4 5 -2 7

13. Apply BACKTRACKING algorithm to travel from A to G.

B C D

E F G Goal

H I J

4:35
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

14. Apply BACKTRACKING algorithm to travel to all nodes.


A

B C

D E F G

15. Apply BACKTRACKING algorithm to travel to all nodes.

B C

D E F G

I J

4:36
MODULE – LECTURE NOTES ISP542/ITS462 SEARCH

16. Based on the following search tree, perform the following search algorithm.
A:10

B:10 C:15 D:8 E:16

F:5 G:6 H:3 I:8 J:6 K:5 L:5

M:8 N:4 O:2 P:5 Q:9 R:5 S:3 T:4 U:6

T:8 U:6 X:5 Y:1

V:5 W:1 Z:8 AA:4 AB:2

a. Hill climbing
b. Best first search

4:37

You might also like