Efficient algorithm to decide if a location is reachable I am designing a game solver. I have a binary $m*n$ Matrix, where $0$ stands for a free space, while $1$ stands for an occupied space. In the game we move a ball that we will call $x$. The ball can only move UP, DOWN, RIGHT or LEFT (no diagonal).

Imagine the following matrix:

$
1 0 0\\
0 1 0\\
x 0 1
$

We see that the ball is in the lower left corner -- which is "trapped".
What efficient algorithm can I use to decide if the ball is trapped, that is if there is no way to get to the other side (like the example given above)?

Another example where the ball is not trapped:

$
1 0 0\\
1 0 0\\
x 0 1
$

I am using bits matrices, I would rather not use graphs if possible.
The problem you're trying to solve is exactly graph connectivity. You don't necessarily need to construct the graph explicitly but this is a graph problem.

By "you don't necessarily need to construct the graph explicitly", I mean that you don't necessarily need to create any new data structures.  Every time your graph algorithm says "vertex", you can think "co-ordinates" and every time it says "neighbour" or "adjacent" or "edge", you can think of the squares above, below, to the left and to the right that contain&nbsp;0.