# Understanding this verifier runs in plynomial time

I'm self studying complexity theory and want to prove that SAT is in NP, so I came up with this verifier for SAT:

\begin{align*} V &= \text{"On input w = \langle \phi, c \rangle}:\\ & \quad \text{1. Test whether c is an assignment for \phi} \\ & \quad \text{2. Test whether c satisfies \phi}\\ & \quad \text{3. If both pass, accept; otherwise, reject."} \end{align*}

It seems that this is supposed to be an easy question but how can I show that this runs in polynomial time in the size of the input, i.e., $$|\langle \phi, c\rangle|$$?

You just need to show that you can evaluate $$\phi$$ in polynomial-time. This is clearly true for any reasonable encoding of $$\phi$$ and $$c$$, but the details depend on the specific encoding you choose.
One of the many possible "natural" encodings could be as follows: $$\phi$$ is encoded by specifying the number of variables $$n$$, the number of clauses $$m$$, and list of clauses, where each clause is a list of literals. Each literal is just a pair whose first element is the index (between $$1$$ and $$n$$) of a variable and the second elements is a boolean that encodes whether the variable is negated. The assignment $$c$$ is an array of $$n$$ boolean values, the $$i$$-th value is the truth value of the $$i$$-th variable.
Then you can just scan the list of clauses. For each clause, scan the list of literals. For each literal check whether the literal is positive and the corresponding variable is set to true in $$c$$, or the literal is negated and the variable is set to false. If no literal in the clause satisfies the above conditions, reject. If you run of clauses without rejecting, accept.
This takes time proportional to $$m+n$$ on the RAM model. If you want to use a Turing machine, describing the algorithm is more annoying and depends on even more fine-grained details of the encoding, but it can be done.
• @Nathaniel, you are right. Then please interpret the answer as an intuitive argument to convince the reader that "it can be done". A convenient encoding of $\phi$ for general SAT formulae could be in the form of a binary expression tree. The algorithm works in phase. At each phase one not-yet-evaluated vertex having only evaluated vertices as children is located and it replaced with its corresponding truth value. At the beginning only leaves are "evaluated". At the end, the value of $\phi$ is the value of the root. The time is quadratic in the tree size (one can do better but this suffices). Nov 7, 2022 at 18:01