Use Bi-directional BFS/DFS to solve a navigation problem.
Problem Statement: Represent a city map as a graph where intersections are nodes and roads are edges. Find the shortest path between two locations.
Size: 538.66 KB
Language: en
Added: Jan 02, 2025
Slides: 11 pages
Slide Content
Bi-Directional BFS/DFS
Dr Hitesh Mohapatra
AssociateProfessor
AI-LAB : Assignment 3
Assignment 3: Route Finder Using Bi-
Directional BFS/DFS
Objective:UseBi-directionalBFS/DFStosolveanavigationproblem.
ProblemStatement:Representacitymapasagraphwhereintersectionsare
nodesandroadsareedges.Findtheshortestpathbetweentwolocations.
Tasks:
•ImplementBi-directionalBFStominimizethenumberofnodesexplored.
•ComparetheperformanceofBi-directionalBFSwithstandardBFSand
DFS.
•Visualizethesearchprocess(e.g.,usingalibrarylikenetworkxinPython).
What is Bi-Directional BFS?
•Insteadofsearchingfromjust
thesourcenode,Bi-Directional
BFSsearchesfromboththe
startandtarget.
•Thesearchstopswhenthetwo
searchesmeetinthemiddle.
•Significantlyreduces the
numberofnodesexplored.
Process
It runs two simultaneous search –
1.Forward search from source/initial vertex toward goal vertex
2.Backward search from goal/target vertex toward source
vertex
Example
Suppose we want to find if
there exists a path from vertex 0
to vertex 14. Here we can
execute two searches, one from
vertex 0 and other from vertex
14. When both forward and
backward search meet at vertex
7, we know that we have found
a path from node 0 to 14 and
search can be terminated now.
We can clearly see that we
have successfully avoided
unnecessary exploration.
When to use bidirectional approach?
We can consider bidirectional approach when-
1.Both initial and goal states are unique and completely
defined.
2.The branching factor is exactly the same in both directions.
Algorithm
while sq != empty and tq != empty
perform next iteration for sq
perform next iteration for tq
save the root of a leaf node in the root array
if we have visited the node of intersection
save it
break
using node of intersection and root node, find the path