3 Solving Problems by Searching
3 Solving Problems by Searching
1 TABLE OF CONTENTS
2 Breadth-first search .............................................................................................................................. 1
3 Uniform-cost search.............................................................................................................................. 2
4 Depth-first search ................................................................................................................................. 2
5 Depth-limited search ............................................................................................................................ 4
6 Iterative deepening depth-first search ................................................................................................. 5
7 Comparison of Uninformed Search Strategies ..................................................................................... 5
8 Summary ............................................................................................................................................... 5
2 BREADTH-FIRST SEARCH
Breadth-First search is like traversing a tree where each node is a state which may a be a potential
candidate for solution. It expands nodes from the root of the tree and then generates one level of the
tree at a time until a solution is found.
The search technique that search a whole depth level the move bellow
A Queue is a linear structure which follows a particular order in which the operations are performed.
The order is First In First Out (FIFO).
Queue Visited
1 1
8,5,2 1,8
5,2,6,4,3 1,8,5
2,6,4,3,9 1,8,5,2
6,4,3,9,10,7 1,8,5,2,6
4,3,9,10,7 1,8,5,2,6,4
3,9,10,7 1,8,5,2,6,4,3
9,10,7 1,8,5,2,6,4,3,9
10,7 1,8,5,2,6,4,3,9,10
7 1,8,5,2,6,4,3,9,7
3 UNIFORM-COST SEARCH
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
4 DEPTH-FIRST SEARCH
The DFS algorithm is a recursive algorithm that uses the idea of backtracking. It involves exhaustive
searches of all the nodes by going ahead, if possible, else by backtracking.
OR
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The
algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph)
and explores as far as possible along each branch before backtracking.
Stack Visited
1 1
2,3 1,2
4,5,3 1,2,4
5,3 1,2,4,5
3 1,2,4,5,3
If three is our destination node then searching will stop
Stacks operate on a last in, first out (LIFO) principle of item access. Think of Last In First Out like having a
stack of papers. Any new piece of paper would go at the top of the pile, but you would also grab your
next piece from the top of the pile as well.
Stack Visited
1 1
8,5,2 1,8
6,4,3,5,2 1,8,6
10,7,4,3,5,2 1,8,6,10
7,4,3,5,2 1,8,6,10,7
4,3,5,2 1,8,6,10,7,4
3,5,2 1,8,6,10,7,4,3
5,2 1,8,6,10,7,4,3,5
2 1,8,6,10,7,4,3,5,2
9 1,8,6,10,7,4,3,5,2,9
If nine is our destination node then searching will stop
5 DEPTH-LIMITED SEARCH
It is depth first search with a limit or depth in the searching
Stack Visited
1 1
8,5,2 1,8
6,4,3,5,2 1,8,6
4,3,5,2 1,8,6,4
3,5,2 1,8,6,4,3
5,2 1,8,6,4,3,5
2 1,8,6,4,3,5,2
9 1,8,6,4,3,5,2,9
8 SUMMARY
Before an agent start searching for solutions, it must formulate a goal and then use the goal to a
problem.
A problem consists of four parts: the initial state, a set of actions, a goal test function, and a
path cost function. The environment of the problem is represented by a state space. A path
through the state space from the initial state to a goal state is a solution. A single, general TREE-
SEARCH algorithm can be used to solve any problem; specific variants of the algorithm embody
different strategies.
Search algorithms are judged on the basis of completeness, optimality, time complex- ity, and
space complexity. Complexity depends on b, the branching factor in the state space, and d, the
depth of the shallowest solution.
Breadth-first search selects the shallowest unexpanded node in the search tree for expansion. It
is complete, optimal for unit step costs, and has time and space complexity of The space
complexity makes it impractical in most cases. Uniform-cost search is similar to breadth-first
search but expands the node with lowest path cost, It is complete and optimal if the cost of each
step exceeds some positive bound Depth-first search selects the deepest unexpanded node in
the search tree expan- sion. It is neither complete nor optimal, and has time complexity of
O(bm) and space complexity of where m is the maximum depth of any path in the state space.
Depth-limited search imposes a fixed depth limit on a depth-first search.
Iterative deepening search calls depth-limited search with increasing limits until a goal is found.
It is complete, optimal for unit step costs, and has time complexity of (bd) and space complexity
of (bd).
Bidirectional search can enormously reduce time complexity, but it is not always ap- plicable and
may require too much space.
When the state space is a graph rather than a tree, it can pay off to check for repeated states in
the search tree. The GRAPH-SEARCH algorithm eliminates all duplicate states. When the
environment is partially observable, the agent can apply search algorithms in the space of belief
states, or sets of possible states that the agent might be in. In some cases, a single solution
sequence can be constructed; in other. cases, the needs a contingency plan to handle unknown
circumstances that may arise.