You are on page 1of 8

BIMS

BARANI INSTITUTE OF MANAGEMENT


SCIENCES

“AI”

 ASSIGNMENT NUMBER 1
 SUBMITTED BY: KAINAT PARVEEN
 REGISTRATION NUMBER: 18-ARID-5163
 BSCS-6A
4. Differentiate between BFS and UCS & BFS and DFS.
ANSWER

Difference between BFS and DFS Binary Tree


BFS DFS

BFS finds the shortest path to the DFS goes to the bottom of a subtree, then
destination. backtracks.

The full form of BFS is Breadth-First Search. The full form of DFS is Depth First Search.

It uses a queue to keep track of the next It uses a stack to keep track of the next
location to visit. location to visit.
BFS traverses according to tree level. DFS traverses according to tree depth.

It is implemented using FIFO list. It is implemented using LIFO list.

It requires more memory as compare to DFS. It requires less memory as compare to BFS.

This algorithm gives the shallowest path This algorithm doesn't guarantee the
solution. shallowest path solution.

There is no need of backtracking in BFS. There is a need of backtracking in DFS.

You can never be trapped into finite loops. You can be trapped into infinite loops.

If you do not find any goal, you may need to If you do not find any goal, the leaf node
expand many nodes before the solution is backtracking may occur.
found.

Difference between BFS and UCS


UCS is different from BFS and DFS because here the costs come into play. In
other words, traversing via different edges might not have the same cost. The
goal is to find a path where the cumulative sum of costs is least.
Cost of a node is defined as:
Cost (node) = cumulative cost of all nodes from root
Cost (root) = 0
Breadth-first search (BFS) is an algorithm for traversing or searching tree or
graph data structures. It starts at the tree root (or some arbitrary node of a
graph, sometimes referred to as a ‘search key’), and explores all of the
neighbor nodes at the present depth prior to moving on to the nodes at the
next depth level.

You might also like