79648509

Date: 2025-06-02 10:00:28
Score: 0.5
Natty:
Report link

βœ… O(1) Reachability Check in 2D Grid Without Flood Fill

While traditional methods like BFS or DFS don’t meet the strict O(1) memory constraint, there is a greedy, deterministic method that can perform real-time reachability checks efficiently β€” and using only 20 integers.

---

πŸ”§ Algorithm: `mgReachabilityCheckGibis`

- No recursion, no allocation

- No caching or preprocessing

- Deterministic behavior

- Uses simple direction logic and wall-following to circumvent obstacles

- Works with O(1) memory, even on 2^60 x 2^60 2D grid

πŸ“‚ Source code:

[https://github.com/MatthiasGibis/2D-Grid-Reachability-Check%5C%5C](https://github.com/MatthiasGibis/2D-Grid-Reachability-Check/blob/main/mgReachabilityCheckGibis.swift)

---

βš™οΈ Performance (tested on Swift/iOS/macOS):

| Grid Size | Clear Path | Obstacle Detour |

|-----------|------------|-----------------|

| 128Γ—128 | 30 ns | ~5 Β΅s |

\> Memory footprint stays constant. No maps, sets, or traversal stacks are used.

---

πŸ“± Benchmark & Visualization

You can try this algorithm live in the free app [`mgSearch`](https://apps.apple.com/de/app/mgsearch/id6744561847) for iPads and macOS devices (Apple Silicon).

- Visualize obstacle layouts

- Benchmark reachability timings

---

Reasons:
  • Whitelisted phrase (-1): try this
  • Long answer (-1):
  • No code block (0.5):
  • Self-answer (0.5):
  • Filler text (0.5): -----------
  • Filler text (0): ------------
  • Filler text (0): -----------------
  • Low reputation (1):
Posted by: Matthias Gibis