Está en la página 1de 5

# Assignment No.

1
Aim: Implement BFS and DFS algorithm for route finding problem.
Objective:
Student will learn:
i)

Uninformed Search

ii)

## iii) To solve Route Finding Problem using BFS and DFS.

Theory:
Uninformed Search Methods:

Uninformed search methods belong to the category of methods that have no prior knowledge of the
problem. They are generally exhaustive methods that are brute force, searching all possible paths. Since
these methods work in the absence of any information, they are also referred to as blind search methods.
These methods can be understood by a very simple example. If would like to search a boy named
Ram in a school, with the number of classes from 1 to 10 and each class having two divisions then the
search would involve going to each and every class till the student named Ram, we are looking for, is
found. Since no information is available, we need to select certain strategy and expand the nodes (here,
the classes) in some predefined order. Bread first search and depth first search are two basic approaches
of expanding and visiting nodes in the absence of any knowledge.
The search technique in BFS follows the shallow node approach. Here the basic idea is that across the
level of the tree, all the nodes are searched. Queue data structure is used to carry out the search, where
things happen on first in first out basis (FIFO).

## ZEAL College of Engineering and Research

Let us take an example of BFS, consider that A is the start state and D is the goal state (Figure 1.2).

A
B
C

D
Figure 1.2 Sample tree input for BFS
In BFS, The step-wise working for the following graph:
Queue

Check

A
Removed A, is it goal? No, add children. So, B and E are added.
BE
E

EC
C

CFG
FG

FGD
GD

## Removed F, is it goal? No, add children.

Cannot be added, leaf node, so remove next node.

## Removed G, is it goal? No, add children.

Cannot be added, leaf node, so remove next node.

Empty

1.

2.

i.

ii.

iii.

## If yes, return the state.

iv.

If not, get the next level nodes, i.e., nodes reachable from the parent and add to node-list.

## Depth-first search (DFS)

In this method, a single branch of the tree is considered at a time, nodes are visited by going through the
depth of the tree from the starting node.

## Figure 1.3 Depth first search tree.

With the start node of A and the goal state of D, we have the DFS approach carried out as follows:

A
B
C

D
Figure 1.4 Sample tree input for DFS.

Stack
Step 1:

Top

## Pop A, is it goal? No, push its children on the stack.

As successor is pushed.

Top

A
Step 2:

Top

E
C

## Pop B, is it goal? No, push its children on the stack.

Bs successor is pushed.

Top

E
Step 3:

Top

E
D

## Pop C, is it goal? No, push its children on the stack.

Cs successor is pushed.

Top

E
Step 4:

Top

## Pop D, is it goal? YES!

E
The depth first search algorithm is summarized as follows:
1.
2.

## If initial state is the final state success : exit

Do till you get success or failure.
i.
Generate a successor, if no more successors can be generated failure.
ii.
Go to state 1 with initial state to be the current generated successor.

Route Finding
Route finding is defined in terms of specified locations and transition along links between them. Let us
consider airline travel planning problem. The objective is to arrive to a destination.
Initial state: Starting point of the journey
Goal state: Final destination
Operators/Actions: Flight from current location to reach the next location.

## ZEAL College of Engineering and Research

Requires less memory than BFS since only need to remember the current path

If lucky, can find a solution without examining much of the state space