Find deviation in grid walk

196 Views Asked by At

I have a problem where one can walk on a rectangular grid of dimensions $m \times n$ and origin $(0,0)$. You can only walk up or right. Though the problem of how many path there are is fairly simple (reference),

I need to find the deviation of any path from the straight path. The deviation of a path is defined as: $$\max\left(\frac{x}{m} - \frac{y}{n}, \frac{y}{n} - \frac{x}{m}\right)$$

What should I consider the straight path? Is it the diagonal line between $(0,0)$ and $(m,n)$?

1

There are 1 best solutions below

2
On BEST ANSWER

The "straight line" distance between the two points is know as the Euclidean distance, and is indeed calculated by $$\sqrt{\left(m-0\right)^2+\left(n-0\right)^2}$$

Now, the formula you've provided is the Chebyshev distance, but what you're actually looking for, since you can only go up or right, is the Manhattan distance. The difference is subtle, but it makes a difference.

The manhattan distance is calculated using the formula $$\mid{m-0}\mid+\mid{n-0}\mid$$

Hope that helps!