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

Discussion Lecture8

Uploaded by

Kanav Arora
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 views25 pages

Discussion Lecture8

Uploaded by

Kanav Arora
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/ 25

11/20/24

Searching Algorithm
CS 165A Section 8

Sirui Zeng

Computer Science Name


Office/Department/Division
Reminder

● HW3 Due Nov. 26 (next Tue.)

Office/Department/Division Name
Outline

● A* Search
● Minimax
● Exercises

Office/Department/Division Name
A* Search
Introduction
● Target: constructs a lowest-cost path tree from the start node to the
target node, much like Dijkstra.
● A* utilizes a function f(n) for each node to estimate the overall cost of a
path: f(n)=g(n)+h(n), where
● Total estimated cost of route across node n is given by f(n).
● g(n) is the cost to go to node n.
● Estimated cost from n to goal is h(n).
● Since this is the heuristic portion of the cost function, it is somewhat of a
guess.

Office/Department/Division Name
A* Search
Introduction

● Admissibility
● h(n) ≤ true cost to reach the goal
● It guarantees the optimality of the A* algorithm.

● Consistency
● For every node n, h(n) ≤ c(n, n’) + h(n’)
● Consistency is a stricter form of admissibility; all consistent heuristic
functions are guaranteed to be admissible.

Office/Department/Division Name
A* Search
Algorithm Overview
1. Initialization
a. Open set (priority queue) initialized with the start node.
b. Closed set (visited nodes) empty.
2. Loop Until Goal Reached
a. Pick node n with the lowest f(n) from the open set.
b. If n is the goal, terminate.
c. Expand n’s neighbors and update costs.
3. Update Costs
a. For each neighbor, calculate g(n), h(n), and f(n).
b. If a better path is found, update and add to the open set.

Office/Department/Division Name
A* Search Exercise
Consider the following graph, with start state S and goal state G. Edge costs are labeled on
the edges, and heuristic values are given by the h values next to each state. In the search
procedures below, break any ties alphabetically, so that if nodes on your fringe are tied in
values, the state that comes first alphabetically is expanded first.

1. What is the path returned by greedy graph search, using the given heuristic?
2. List the nodes in the order they are expanded by A* graph search.
3. What is the path returned by A* graph search?
4. Is this heuristic admissible? Is it consistent?

Office/Department/Division Name
A* Search Exercise
Consider the following graph, with start state S and goal state G. Edge costs are labeled on
the edges, and heuristic values are given by the h values next to each state. In the search
procedures below, break any ties alphabetically, so that if nodes on your fringe are tied in
values, the state that comes first alphabetically is expanded first.

1. What is the path returned by greedy graph search, using the given heuristic?
2. List the nodes in the order they are expanded by A* graph search.
3. What is the path returned by A* graph search?
4. Is this heuristic admissible? Is it consistent?

S →A→G

Office/Department/Division Name
A* Search Exercise
Consider the following graph, with start state S and goal state G. Edge costs are labeled on
the edges, and heuristic values are given by the h values next to each state. In the search
procedures below, break any ties alphabetically, so that if nodes on your fringe are tied in
values, the state that comes first alphabetically is expanded first.

1. What is the path returned by greedy graph search, using the given heuristic?
2. List the nodes in the order they are expanded by A* graph search.
3. What is the path returned by A* graph search?
4. Is this heuristic admissible? Is it consistent?

Order: S,A,C,B,G

Office/Department/Division Name
A* Search Exercise
Consider the following graph, with start state S and goal state G. Edge costs are labeled on
the edges, and heuristic values are given by the h values next to each state. In the search
procedures below, break any ties alphabetically, so that if nodes on your fringe are tied in
values, the state that comes first alphabetically is expanded first.

1. What is the path returned by greedy graph search, using the given heuristic?
2. List the nodes in the order they are expanded by A* graph search.
3. What is the path returned by A* graph search?
4. Is this heuristic admissible? Is it consistent?

S →A→C→G

Office/Department/Division Name
A* Search Exercise
Consider the following graph, with start state S and goal state G. Edge costs are labeled on
the edges, and heuristic values are given by the h values next to each state. In the search
procedures below, break any ties alphabetically, so that if nodes on your fringe are tied in
values, the state that comes first alphabetically is expanded first.

1. What is the path returned by greedy graph search, using the given heuristic?
2. List the nodes in the order they are expanded by A* graph search.
3. What is the path returned by A* graph search?
4. Is this heuristic admissible? Is it consistent?

Admissible,
But not consistent

Office/Department/Division Name
Minimax
Introduction
● In this algorithm two players play the game, one is called MAX and
other is called MIN.
● Both the players fight it as the opponent player gets the minimum
benefit while they get the maximum benefit.
● Both Players of the game are opponent of each other, where MAX will
select the maximized value and MIN will select the minimized value.
● The minimax algorithm performs a depth-first search algorithm for the
exploration of the complete game tree.
● The minimax algorithm proceeds all the way down to the terminal node
of the tree, then backtrack the tree as the recursion.

Office/Department/Division Name
Minimax
Pseudo-code

Office/Department/Division Name
Minimax Exercise
Consider a modification of a game tree where, rather than numbers, leaf nodes are now
intervals, given by [lower, upper], and where the true value is somewhere inside the interval.
Suppose the min and max players are both trying to optimize avg(lower,upper); that is, max
is trying to maximize the average value of the interval chosen and min is trying to minimize it.
1. In each node of the tree above, fill in the interval defining what the agent knows about
the value of that node.
2. In the tree above, cross out the leaves that would be pruned by alpha-beta pruning
based on average values.

Office/Department/Division Name
Minimax Exercise
Consider a modification of a game tree where, rather than numbers, leaf nodes are now
intervals, given by [lower, upper], and where the true value is somewhere inside the interval.
Suppose the min and max players are both trying to optimize avg(lower,upper); that is, max
is trying to maximize the average value of the interval chosen and min is trying to minimize it.

1. In each node of the tree above, fill in the interval defining what the agent knows about
the value of that node.

Office/Department/Division Name
Minimax Exercise
Consider a modification of a game tree where, rather than numbers, leaf nodes are now
intervals, given by [lower, upper], and where the true value is somewhere inside the interval.
Suppose the min and max players are both trying to optimize avg(lower,upper); that is, max
is trying to maximize the average value of the interval chosen and min is trying to minimize it.

2. In the tree above, cross out the leaves that would be pruned by alpha-beta pruning
based on average values.

Office/Department/Division Name
Exercises
Problem 1
If f(s), g(s) and h(s) are all admissible heuristics then which of the following are also
guaranteed to be admissible heuristics:

Office/Department/Division Name
Exercises
Problem 1
If f(s), g(s) and h(s) are all admissible heuristics then which of the following are also
guaranteed to be admissible heuristics:

Office/Department/Division Name
Exercises Problem 2
(a) Consider the class of directed, m × n grid graphs as illustrated above. (We assume that
m,n > 2.) Each edge has a cost of 1. The start state is A11 at top left and the goal state at
Amn is bottom right.
1. If we run Uniform-Cost graph search (breaking ties randomly), what is the maximum
possible size of the fringe?
2. If we run Depth-First graph search with a stack, what is the maximum possible size of
the stack?

Office/Department/Division Name
Exercises Problem 2
(a) Consider the class of directed, m × n grid graphs as illustrated above. (We assume that
m,n > 2.) Each edge has a cost of 1. The start state is A11 at top left and the goal state at
Amn is bottom right.
1. If we run Uniform-Cost graph search (breaking ties randomly), what is the maximum
possible size of the fringe?
2. If we run Depth-First graph search with a stack, what is the maximum possible size of
the stack?

Office/Department/Division Name
Exercises Problem 2
(a) Consider the class of directed, m × n grid graphs as illustrated above. (We assume that
m,n > 2.) Each edge has a cost of 1. The start state is A11 at top left and the goal state at
Amn is bottom right.
1. If we run Uniform-Cost graph search (breaking ties randomly), what is the maximum
possible size of the fringe?
2. If we run Depth-First graph search with a stack, what is the maximum possible size of
the stack?

Office/Department/Division Name
Exercises Problem 2
(b) Now answer the same questions for undirected m×n grid graphs (i.e., the links go in both
directions between neighboring nodes).
1. If we run Uniform-Cost graph search (breaking ties randomly), what is the maximum
possible size of the fringe?
2. If we run Depth-First graph search with a stack, what is the maximum possible size of
the stack?

Office/Department/Division Name
Exercises Problem 2
(b) Now answer the same questions for undirected m×n grid graphs (i.e., the links go in both
directions between neighboring nodes).
1. If we run Uniform-Cost graph search (breaking ties randomly), what is the maximum
possible size of the fringe?
2. If we run Depth-First graph search with a stack, what is the maximum possible size of
the stack?

Office/Department/Division Name
Exercises Problem 2
(b) Now answer the same questions for undirected m×n grid graphs (i.e., the links go in both
directions between neighboring nodes).
1. If we run Uniform-Cost graph search (breaking ties randomly), what is the maximum
possible size of the fringe?
2. If we run Depth-First graph search with a stack, what is the maximum possible size of
the stack?

Office/Department/Division Name
Office/Department/Division Name

You might also like