Skip to content

Find the shortest path between two points in a unweighted grid with obstacles

Notifications You must be signed in to change notification settings

zhaohuabing/shortest-path-in-grid-with-obstacles-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Find the shortest path between two points in a unweighted grid with obstacles

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages