Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find multidimensional path of exact 0 cost with 1, 0, -1 weights

I was given directed graph with n nodes and edges with weigths of vectors (every vector has length m) of numbers 1, 0, -1. I would like to find any path (or say that such path doesn't exist) from one node to other (we can visit nodes many times) such that sum of its weights equals to vector of only zeros. I was thinking of brute-force backtracking algorithm but it is not guaranteed that it would end. Can we somehow limit length of such path in terms of n and m? Example of graph for n=8, m=2

enter image description here

Example of path

enter image description here

like image 866
Kacper Kowalski Avatar asked Apr 29 '19 17:04

Kacper Kowalski


1 Answers

We can upper bound the length of the path, by noting that if such a path exists it must consists of a mix of a simple path and some cycles. Each of those paths can have at most lenght n. For each cycle we can effectively apply a vector that corrispond to the change that happens by going through one of such cycles. We can only construct m cycles that are linearly indepednt of each other (note that we might need to go in both directions), which is sufficient to cover any vector that the simple path itself costs, so we can resolve any residual by going through each cycle the right amount of times (this relies on the cost of such an edge). The amount of times we have to go through the different cycles is upper bounded by something equivalent to the lowest common multiplier for the effective lengths of each of the vectors effects of the different cycles, which has the (rough) assymtotic bound O(n^2m). If this upper bound holds (you can construct a case reasonably close to it by sperating n into m regions of size roughly n/m, and then have them prime number lengths counting down from n/m, and then chain their dependencies together, which would give ´O((n/m)^m)`), then the solution as exponential size, which means any algorithm that uses (and reports) uncompressed path lengths would not fit in PSPACE (which is a superset of P and NP).

like image 58
Ninetails Avatar answered Oct 20 '22 20:10

Ninetails