Unit 3 Informed and Uninformed Search
Unit 3 Informed and Uninformed Search
A solution is a sequence of actions from initial to goal state. Optimal solution has the lowest path
cost.
A search problem
Figure below contains a representation of a map. The nodes represent cities, and the links
represent direct road connections between cities.
The search problem is to find a path from a city J to a city G
In the case of the uninformed search methods the order in which potential solution paths are
considered is arbitrary, using no domain-specific information to judge where the solution is likely to
lie.
In the case of the heuristically informed search methods one uses domain-dependent (heuristic)
information in order to search the space more efficiently.
• Time Complexity
– How long (worst or average case) does it take to find a solution? Usually measured in terms of the
number of nodes expanded
• Space Complexity
– How much space is used by the algorithm? Usually measured in terms of the maximum number
of nodes in memory at a time
• Optimality/Admissibility
– If a solution is found, is it guaranteed to be an optimal one? For example, is it the one with
minimum cost?
Time complexity:
– Assume a state space where every state has b successors.
– root has b successors, each node at the next level has again b successors (total b2), …
– Assume solution is at depth d
– Worst case; expand all except the last node at depth d
– Total no. of nodes generated:
b + b2 + b3 + ………………….. bd + ( bd+1 –b) = O(bd+1)
Space complexity:
– Each node that is generated must remain in memory
– Total no. of nodes in memory:
1+ b + b2 + b3 + ………………….. bd + ( bd+1 –b) = O(bd+1)
create a queue Q
while Q is non-empty
Two lessons:
– Memory requirements are a bigger problem than its execution time.
– Exponential complexity search problems cannot be solved by uninformed search methods for
any but the smallest instances.
Uniform Cost Search is the best algorithm for a search problem, which does not involve the use
of heuristics. It can solve any general graph for optimal cost. Uniform Cost Search as it sounds
searches in branches which are more or less the same in cost.
Uniform Cost Search again demands the use of a priority queue. Recall that Depth First Search
used a priority queue with the depth upto a particular node being the priority and the path from
the root to the node being the element stored. The priority queue used here is similar with the
priority being the cumulative cost upto the node. Unlike Depth First Search where the maximum
Time complexity;
– Let m is the maximum depth of the search tree. In the worst case Solution may exist at depth
m.
– root has b successors, each node at the next level has again b successors (total b2), …
– Worst case; expand all except the last node at depth m
– Total no. of nodes generated:
b + b2 + b3 + ………………….. bm = O(bm)
Space complexity:
– It needs to store only a single path from the root node to a leaf node, along with remaining
unexpanded sibling nodes for each node on the path.
– Total no. of nodes in memory:
1+ b + b + b + ………………….. b m times = O(bm)
DFS(G, u)
u.visited = true
for each v ∈ G.Adj[u]
if v.visited == false
DFS(G,v)
init() {
For each u ∈ G
u.visited = false
For each u ∈ G
DFS(G, u)
}
Depth-limited search
It makes arbitrary depth limit l and makes DFS upto that limit. It means nodes at depth l are
treated as if they have no successor and after this limit no nodes are visited.
It is DF-search with depth limit l. Solves the infinite-path problem of DFS. Yet it introduces
another source of problem if we are unable to find good guess of l. Let d is the depth of
shallowest solution.
If l < d then incompleteness results.
If l > d then not optimal.
Time complexity: O ( bl )
Space complexity: O ( bl )
Limit = 0
Limit = 1
Limit = 2
ID search evaluation
Completeness:
– YES (no infinite paths)
Time complexity:
– Algorithm seems costly due to repeated generation of certain states.
– Node generation:
level d: once
level d-1: 2
level d-2: 3
…
level 2: d-1
level 1: d
– Total no. of nodes generated:
d.b +(d-1). b2 + (d-2). b3 + …………………..+1. bd = O(bd)
Space complexity:
– It needs to store only a single path from the root node to a leaf node, along with remaining
unexpanded sibling nodes for each node on the path.
– Total no. of nodes in memory:
Optimality:
– YES if path cost is non-decreasing function of the depth of the node.
Note:-
Notice that BFS generates some nodes at depth d+1, whereas IDS does not. The result is that IDS
is actually faster than BFS, despite the repeated generation of node.
Example:
Num. of nodes generated for b=10 and d=5 solution at far right
N(IDS) = 50 + 400 + 3000 + 20000 + 100000 = 123450
N(BFS) = 10 + 100 + 1000 + 10000 + 100000 + 999990 = 1111100
In addition to initial state and goal state, Heuristic Search uses domain-dependent (heuristic)
information like estimated path cost from initial state to goal state in order to search the space
more efficiently. Heuristic function is the estimated cost that defines the goodness of a node to
be expanded next. This allows to search in best path. It does this by deciding which node to
expand next, instead of doing the expansion in a strictly breadth-first or depth-first order. It can
discard or prune certain nodes from search space also.
Optimality:
– Greedy search is not optimal. Same as DFS.
Time complexity:
– In worst case Greedy search is same as DFS therefore it’s time complexity is O(bm).
Space Complexity:
– Space complexity of DFS is O(bm). No nodes can be deleted from memory.
A * Search
Like all informed search algorithms, it first searches the routes that appear to be most likely to
lead towards the goal. What sets A* apart from a greedy best-first search is that it also takes the
distance already traveled into account (the g(n) part of the heuristic is the cost from the start, and
not simply the local cost from the previously expanded node).The algorithm traverses various
paths from start to goal. Evaluation function used by A* search algorithm is
f(n) = h(n) + g(n)
Where:
g(n): the actual shortest distance traveled from initial node to current node
h(n): the estimated (or "heuristic") distance from current node to goal
f(n): the sum of g(n) and h(n)
Optimality:
– A* search gives optimal solution when the heuristic function is admissible heuristic.
Time complexity:
– Exponential with path length i.e. O(bd) where d is length of the goal node from start node.
Space complexity:
– It keeps all generated nodes in memory. Hence space is the major problem not time
Admissible heuristic
A heuristic function is said to be admissible heuristic if it never overestimates the cost to reach to
the goal.
i.e
h(n) ≤ h*(n)
Where
h(n) = Estimated cost to reach to the goal node from node n
h*(n) = Actual cost to reach to the goal node from node n
#Prove that A* search gives optimal solution when the heuristic is admissible.
Suppose suboptimal goal G2 in the queue.
Let n be an unexpanded node on a shortest to optimal goal G and C* be the cost of optimal goal
node.
# Prove that: If h(n) is consistent , then the values of f(n) along the path are non-decreasing.
Hill climbing
Hill climbing is depth-first search with a heuristic measurement that orders choices as nodes are
expanded. It always selects the most promising successor of the node last expanded.
In this search method, we start with a partial solution and try to improve it for better solution
The relative simplicity of the algorithm makes it a popular first choice amongst optimizing
algorithms.
Hill climbing can often produce a better result than other algorithms when the amount of time
available to perform a search is limited, such as with real-time systems, so long as a small
number of increments typically converges on a good solution (the optimal solution or a close
approximation).
From the graph, S moves to B because it seems much closer to the goal than A (cost doesn't
matter). A and C seems equi-distance, so goes to the A by heuristics. Then to D and finally G.
Hill climbing cannot reach the optimal/best state (global maximum) if it enters any of the
following regions:
Local maximum: At a local maximum all neighboring states have a value which is worse than
the current state. Since hill climbing uses greedy approach, it will not move to the worse state
and terminate itself. The process will end even though a better solution may exist. Ridge is a
sequence of local maxima
To overcome local maximum problem: Utilize backtracking technique. Maintain a list of
visited states. If the search reaches an undesirable state, it can backtrack to the previous
configuration and explore a new path.
Plateau: This is an area where the search space is flat so that all neighbors return the same
evaluation. On plateau all neighbors have same value. Hence, it is not possible to select the best
direction.
To overcome plateaus: Make a big jump. Randomly select a state far away from current state.
Chances are that we will land at a non-plateau region
Ridge: Any point on a ridge can look like peak because movement in all possible directions is
downward. Hence the algorithm stops when it reaches this state.
To overcome Ridge: In this kind of obstacle, use two or more rules before testing. It implies
moving in several directions at once.
A monkey is in a room. Suspended from the ceiling is a bunch of bananas, beyond the monkey's
reach. However, in the room there are also a chair and a stick. The ceiling is just the right height
so that a monkey standing on a chair could knock the bananas down with the stick. The monkey
knows how to move around, carry other things around, reach for the bananas, and wave a stick in
the air. What is the best sequence of actions for the monkey?
There are many applications of this problem. One is as a toy problem for computer science.
Another possible purpose of the problem is to raise the question: Are monkeys intelligent?
Both humans and monkeys have the ability to use mental maps to remember things like where to
go to find shelter, or how to avoid danger. They can also remember where to go to gather food
and water, as well as how to communicate with each other.
Simulated Annealing
It is motivated by the physical annealing process in which material is heated and slowly cooled
into a uniform structure. Compared to hill climbing the main difference is that SA allows
downwards steps. Simulated annealing also differs from hill climbing in that a move is selected
at random and then decides whether to accept it. If the move is better than its current position
then simulated annealing will always take it. If the move is worse (i.e. lesser quality) then it will
be accepted based on some probability. The probability of accepting a worse state is given by the
equation
P = exp(-c /t) > r
Where
c = the change in the evaluation function
t = the current value
Game Search
Games are a form of multi-agent environment
– What do other agents do and how do they affect our success?
– Cooperative vs. competitive multi-agent environments.
– Competitive multi-agent environments give rise to adversarial search often known as games
Games – adversary
– Solution is strategy (strategy specifies move for every possible opponent reply).
– Time limits force an approximate solution
– Evaluation function: evaluate ―goodness‖ of game position
– Examples: chess, checkers, Othello, backgammon
Difference between the search space of a game and the search space of a problem: In the first
case it represents the moves of two (or more) players, whereas in the latter case it represents the
"moves" of a single problem-solving agent
Min-max algorithm allows us to determine the best move that maximizes the winning situation
of a player. This algorithm assumes the zero sum game. If a player A is trying to maximize the
cost then other player tries to minimize the cost. The game must be adversary. It means no player
makes wrong move. In min-max algorithm we look ahead for some states and construct the game
tree. Each node in the game tree represents the various situations in the game. There may be two
types of nodes namely max and min node. Let max node represent the turn of player A and min
node represents the turn of Player B. Max node always backs off with the maximum value of its
children and min node backs off minimum value of its children. At the terminal of game tree,
some heuristics is assigned. The heuristics is goodness for the player A for winning the game.
After this we traverse the tree in DFS manner and values are backed off by min and max nodes
according to their purpose up to the root node. The Player A then takes the move which
maximizes the its winning situation.
- the value of a node where it is the turn of player O to move is the minimum of the values of its
successors (because O tries to minimize the outcome of X).
Figure below shows how the values of the nodes of the search tree are computed from the values
of the leaves of the tree.
The values of the leaves of the tree are given by the rules of the game:
• 1 if there are three X in a row, column or diagonal;
• -1 if there are three O in a row, column or diagonal;
• 0 otherwise
An alpha cutoff
To apply this technique, one uses a parameter called alpha that represents a lower bound for the
achievement of the Max player at a given node.
Let us consider that the current board situation corresponds to the node A in the following figure.
The minimax method uses a depth-first search strategy in evaluating the descendants of a node. It
will therefore estimate first the value of the node B. Let us suppose that this value has been
evaluated to 15, either by using a static evaluation function, or by backing up from descendants
omitted in the figure. If Max will move to B then it is guaranteed to achieve 15. Therefore 15 is a
lower bound for the achievement of the Max player (it may still be possible to achieve more,
depending on the values of the other descendants of A). Therefore, the value of α at node B is 15.
This value is transmitted upward to the node A and will be used for evaluating the other possible
moves from A.
One should notice that E may itself have a huge sub tree. Therefore, the elimination of E means,
in fact, the elimination of this sub tree.
A beta cutoff
To apply this technique, one uses a parameter called beta that represents an upper bound for the
achievement of the Max player at a given node.
In the above tree, the Max player moved to the node B. Now it is the turn of the Min player to
decide where to move:
Let us assume that the value of F has been evaluated to 15. From the point of view of Min, this is
an upper bound for the achievement of Min (it may still be possible to make Min achieve less,
depending of the values of the other descendants of B). Therefore the value of β at the node F is
To evaluate the node G, its left-most child H is evaluated first. Let us assume that the value of H
is 25 (this value has been obtained either by applying a static evaluation function directly to H, or
by backing up values from descendants omitted in the figure). Because this value is greater than
the value of β, the best move for Min is to node F, independent of the value of node I that need
not be evaluated. Indeed, if the value of I is v ≥ 25, then Max (in G) will move to I. Otherwise, if
the value of I is less than 25, Max will move to H. So in both cases, the value obtained by Max is
at least 25 which is greater than β (the best value obtained by Max if Min moves to F).
Therefore, the best move for Min is at F, independent of the value of I. The elimination of the
node I is a beta cutoff.
One should notice that by applying alpha and beta cut-off, one obtains the same results as in the
case of mini-max, but (in general) with less effort. This means that, in a given amount of time,
one could search deeper in the game tree than in the case of mini-max.
Game of chance
A game of chance is a game whose outcome is strongly influenced by some randomizing device,
and upon which contestants may choose to wager money or anything of monetary value.
Common devices used include dice, spinning tops, playing cards, roulette wheels, or numbered
balls drawn from a container. A game of chance may have some skill element to it, however,
chance generally plays a greater role in determining the outcome than skill. A game of skill, on
the other hand, also may have elements of chance, but with skill playing a greater role in
determining the outcome.
Examples: card playing, dice rolling, coin flipping, gambling games
Game Theory
Game theory is a framework for hypothetical social situations among competing players. In some
respects, game theory is the science of strategy, or at least the optimal decision-making of
independent and competing actors in a strategic setting. The key pioneers of game theory were
mathematicians John von Neumann and John Nash, as well as economist Oskar Morgenstern.
The focus of game theory is the game, which serves as a model of an interactive situation among
rational players. The key to game theory is that one player's payoff is contingent on the strategy
implemented by the other player. The game identifies the players' identities, preferences, and
available strategies and how these strategies affect the outcome. Depending on the model,
various other requirements or assumptions may be necessary.
The most favorable strategy is to not confess. However, neither is aware of the other's strategy
and without certainty that one will not confess, both will likely confess and receive a 5-year
prison sentence.
The constraint satisfaction problem is to find, for each i from 1 to n, a value in Di for xi so that
all constraints are satisfied. Means that, we must find a value for each of the variables that
satisfies all of the constraints.
A CS problem can easily be stated as a sentence in first order logic, of the form:
(exist x1)..(exist xn) (D1(x1) & .. Dn(xn) => C1..Cm)
A CS problem is usually represented as an undirected graph, called Constraint Graph where the
nodes are the variables and the edges are the binary constraints. Unary constraints can be
disposed of by just redefining the domains to contain only the values that satisfy all the unary
constraints. Higher order constraints are represented by hyper arcs. In the following we restrict
our attention to the case of unary and binary constraints.
Constraints
-- A constraint is a relation between a local collection of variables.
-- The constraint restricts the values that these variables can simultaneously have.
-- For example, all-diff(X1, X2, X3). This constraint says that X1, X2, and X3 must take on
different values. Say that {1,2,3} is the set of values for each of these variables then:
Example: In N-Queens: Place N queens on an NxN chess board so that queen can attack any
other queen.
The value of Qi and Qj are the rows the queens are to be placed in.
Solutions:
o A solution to the N-Queens problem will be any assignment of values to the variables
Q1,…,QN that satisfies all of the constraints.
o Constraints can be over any collection of variables. In N-Queens we only need binary
constraints---constraints over pairs of variables.
Bidirectional search
The idea behind bidirectional search is to run two simultaneous BFS one from initial state and
other backward from goal state. This stops when the two searches meet with some common node
that provides path from initial state to goal state. One or of the search can check if the node is in
the fringe of another search tree before expanding it. If so, the path is found.
Time complexity is 2 O(bd/2) i.e O(bd/2)
Space complexity. At least one of the search tree must be kept in memory to check membership.
Thus space complexity is O(bd/2)
--problem is divided into sub problems where sub problems can be solved separately.
General Rules:
1. Each alphabet takes only one number from 0 to 9 uniquely.
2. Two single digit numbers sum can be maximum 19 with carryover. So carry over in problems
of two number addition is always 1.
3. Try to solve left most digit in the given problem.
4. If a × b = kb, then the following are the possibilities
(3 × 5 = 15; 7 × 5 = 35; 9 × 5 = 45)
Solved Example 1:
The following questions are based on the following multiplication, where each digit has been
replaced by an alphabet.
Solved Example 2:
From the multiplication below, What is the value of NAME?
Solved Example 3:
If SEND + MORE = MONEY then find the respective values
Explanation:
Addition of two numbers with 'n' digits, results in a n+1 digits, then the left most place always =
1.
So M=1. Substitute this value.
Now 'o' cannot be 1 as M already 1. It may not be 2 either as S+1 = 12 or 1 + S + 1 = 12 in the
both cases S is a two digit number. So 'o' is nothing but zero. Put o = 0.
Now S can be either 8 or 9. If S = 8, then there must be a carry over.
E + 0 = 10 + N or 1 + E + 0 = 10 + N
In the above two cases, E - N = 10 is not possible and E - N = 9 not possible as as N cannot be
zero.
So E = 9.
Now E + 0 = N is not possible as E = N. So 1 + E = N possible.
Solved Example 4:
Find the values of all the alphabets if each alphabet represent a single digit from 0 - 9
Explanation:
Let us name the columns as below
We know that sum of two single digit alphabets should not cross 18, and maximum difference
between two alphabets is 9.
If we add two maximum 4 digit numbers the sum is maximum 19998. So the digit in the 5th left
is 1.
Now from the 1st column 1 + E = 1F; if there is any carry over from the 2nd column 1 + 1 + E =
1F
But 1F is a two digit number in alphanumeric is equal to 10 + F
So 1+E=10+F⇒E−F=91+E=10+F⇒E−F=9
From this relatlion we know that E = 9, F = 0
or 1+1+E=10+F⇒E−F=81+1+E=10+F⇒E−F=8
E = 9, F = 1 or E = 8, F = 0
From the above we can infer that F = 0 but we dont know whether E is equal to either 8 or
9. But surely F is not equal to 1 as we fixed already A = 1
Now from the 3rd column,
2C= 1 ⇒ C = 1/2
1 + 2C = 1 ⇒ C = 0
If the sum is a two digit number then
2C = 11 ⇒ C= 11/2