i
want a program in java that finds the shortest path in a 2D array
with obstacles...
60.1K
Verified Solution
Link Copied!
Question
Programming
iwant a program in java that finds the shortest path in a 2D arraywith obstacles from source to destination
using BFS and recursion. The path must be stored in aqueue.
The possible moves are left,right,up and down.
Answer & Explanation
Solved by verified expert
3.6 Ratings (369 Votes)
Using BFS Java program to find the shortest path between a given source cell to a destination cell import javautil class example static int ROW 9 static int COL 10 To store matrix cell cordinates static class Point int x int y public Pointint x int y thisx x thisy y A Data Structure for queue used in BFS static class queueNode Point pt The cordinates of a cell int dist cells distance of from the source public queueNodePoint pt int dist thispt pt thisdist dist check whether given cell row col is a valid cell or not static boolean isValidint row int col return true if row number and column number is in range return row 0 row ROW col 0 col COL These arrays are used to get row and column numbers of 4 neighbours of a given cell static int rowNum 1 0 0 1 static int colNum 0 1 1 0 function to find the shortest path between a given source
See Answer
Get Answers to Unlimited Questions
Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!
Membership Benefits:
Unlimited Question Access with detailed Answers
Zin AI - 3 Million Words
10 Dall-E 3 Images
20 Plot Generations
Conversation with Dialogue Memory
No Ads, Ever!
Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!