https://github.com/zhaohuabing/shortest-path-in-grid-with-obstacles-java
Find the shortest path between two points in a unweighted grid with obstacles
https://github.com/zhaohuabing/shortest-path-in-grid-with-obstacles-java
bfs breadth-first-search grid java obstacle
Last synced: about 1 year ago
JSON representation
Find the shortest path between two points in a unweighted grid with obstacles
- Host: GitHub
- URL: https://github.com/zhaohuabing/shortest-path-in-grid-with-obstacles-java
- Owner: zhaohuabing
- Created: 2019-04-29T03:24:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-22T04:21:14.000Z (almost 3 years ago)
- Last Synced: 2025-02-11T09:47:49.969Z (over 1 year ago)
- Topics: bfs, breadth-first-search, grid, java, obstacle
- Language: Java
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# shortest-path-in-a-grid-with-obstacles-java
Find the shortest path between two points in a unweighted grid with obstacles
Based on breadth first searchalgorithm
test case
* 9 marks the two points between which we need to find the path
* 0 marks the obstacles which the path can't go through
* 1 marks the noraml points which the path can go through
* the length between any two adjacent points is 1
```
9'''''|'''''|'''''|''''':'''''|'''''|'''''`.
| | | | | | | |
| | | | | | | |
|'''''0'''''|'''''|'''''|'''''0'''''|'''''''
| | | | | | | |
| | | | | | | |
|.....|.....|.....0.....|.....|.....|......|
| | | | | | | |
| | | | | | | |
0-----+-----0-----+-----0-----+-----+------|
| | | | | | | |
| | | | | | | |
|'''''|'''''|'''''|'''''|'''''9'''''|''''''|
| | | | | | | |
' | | | | | | |
`-----------0-----'-----'-----'-----'------'
```
The above graph can be represented by a two-dimensional array like this:
```
9 1 1 1 1 1 1 1
1 0 1 1 1 0 1 1
1 1 1 0 1 1 1 1
0 1 0 1 0 1 1 1
1 1 1 1 1 9 1 1
1 1 0 1 1 1 1 1
```
There are two shortest paths between these two points, one is marked with *, the other is marked with #.
```
9 # # # # 1 1 1
* 0 1 1 # 0 1 1
* * 1 0 # # 1 1
0 * 0 1 0 # 1 1
1 * * * * 9 1 1
1 1 0 1 1 1 1 1
```