I am reading Sipser's Introduction to the Theory of Computation, and have trouble understanding the difference between polynomial and non-polynomial problems. When describing a PATH problem, where
PATH = {(G, s, t)| G is a directed graph that has a directed path from s to t}
the author says that using a BFS algorithm to this problem is polynomial. The algorithm is as follows:
M = “On input (G, s, t), where G is a directed graph with nodes s and t:
- Place a mark on node s.
- Repeat the following until no additional nodes are marked:
- Scan all the edges of G. If an edge (a, b) is found going from a marked node a to an unmarked node b, mark node b.
- If t is marked, accept. Otherwise, reject.”
In the next example, the author described a problem of determining whether 2 numbers are relatively prime, where
RELPRIME = {(x, y) | x and y are relatively prime}.
The author argues that if we iterate from 1 to min(n, k), and check if each number divides both x and y, the algorithm would be exponential because
the magnitude of a number represented in binary, or in any other base k notation for k ≥ 2, is exponential in the length of its representation.
Why doesn't the same argument aply to the PATH problem? The nodes have to be indexed and would have to be represented using the same representation, so why isn't this algorithm exponential as well? What about iterating from 1 to n, and printing each number, is that also an exponential algorithm?
Thanks