I'm trying to understand how problems are categorized in these two classes. I have a specific problem I'm looking at, the directed path problem: PATH = $\{\langle G,s,t \rangle | G$ is a directed graph that has a directed path from $s$ to $t$$\}$. The algorithm that's said to run in polynomial time is described as follows:
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$.
I'm just having trouble understanding how this runs in polynomial time and why it runs in polynomial time. Because it seems like this would be no different than a brute-force search which actually runs exponential.
Any clarification on the problem would be highly appreciated.
There are at most $N^2$ edges in a directed graph on $N$ vertices (think in terms of an adjacency matrix), so each iteration of the loop takes $O(N^2)$ time to scan all the edges and at each edge check if the endpoint of the edge is marked (the check for marked-ness/marking a node is $O(1)$ ). Each iteration must mark at least one more node to continue, so there are at most $N$ iterations (since there are $N$ nodes), so the overall algorithm is at most $O(N^3)$ with the final check for $t$ being marked being $O(1)$.