\documentstyle[12pt,twoside,psfig,amssymb]{article}
\input{/a/class/6.045/6045-spring-92/handouts/defs-6045}






\newcommand{\poly}{{\Bbb P}}
\newcommand{\RP}{{\Bbb RP}}
\newcommand{\nat}{{\Bbb N}}
\newcommand{\fa}{\forall}
\newcommand{\sig}{\Sigma}
\newcommand{\arr}{\rightarrow}
\newcommand{\pless}{\leq_{\poly}}


\begin{document}

\handout{lecture28}{Notes on Lecture 28 (4/13/92)}{April 22, 1992}

\section{Easy and Hard Problems}

Last time we argued that the class $\poly$ corresponds well with what
we can feasibly compute.  But sometimes it is difficult to tell when a
particular problem is in $\poly$ or not.  Theoreticians spend a good
deal of time trying to determine whether particular problems are in
$\poly$.  To demonstrate how difficult it can be to make this
determination, we will survey a number of problems today, some of
which are known to be in $\poly$, and some of which we think are
probably not in $\poly$.  The difference between the two types of
problem can be surprisingly small.

Throughout the following, an ``easy'' problem is one that is solvable
in polynomial time, while a ``hard'' problem is one that we think
cannot be solved in polynomial time.

{\bf Easy: Map 2-colorability}. 
\begin{quote}
INPUT: a map (as a graph $G=(V,E)$). See Figure \ref{fig:map}. \\
DECIDE: Can this map be colored with 2 colors so that no two adjacent
countries have the same color? 
\end{quote}

To solve this problem, we simply color the first country arbitrarily.
This forces the colors of neighboring countries to be the other color,
which in turn forces the color of the countries neighboring those
countries, and so on.  If we reach a country which borders two
countries of different color, we will know that the map cannot be
two-colored; otherwise, we will produce a two coloring.  So this
problem is easily solvable in polynomial time.


\begin{figure}[h]
\centerline{\mbox{\psfig{figure=map-fig.ps,height=1in}}}
\caption{A Map and its graph representation}
\label{fig:map}
\end{figure}

{\bf Hard: Map 3-colorability}. 
\begin{quote}
INPUT: a map (as a graph $G=(V,E)$). \\
DECIDE: Can this map be colored with 3 colors so that no two adjacent
countries have the same color? 
\end{quote}

Although this problem seems very similar to the problem above, in fact
it turns out to be much harder.  No one knows how this problem can be
solved in polynomial time.

{\bf Easy: Map 4-colorability}. 
\begin{quote}
INPUT: a map (as a graph $G=(V,E)$). \\
DECIDE: Can this map be colored with 4 colors so that no two adjacent
countries have the same color? 
\end{quote}

Here we have an easy problem again.  By a famous theorem in
mathematics, any map can be four-colored.  It turns out that finding
such a coloring is not that difficult either.

{\bf Easy: Eulerian Tours}. 
\begin{quote}
INPUT: A graph $G=(V,E)$. \\
DECIDE: Is there a path that crosses every edge exactly once and
returns to its starting point? 
\end{quote}

Another famous mathematical theorem comes to our rescue.  If the graph
is connected and every vertex has even degree, then the graph is
guaranteed to have such a tour.  The algorithm to find the tour is a
little trickier, but still doable in polynomial time.

{\bf Hard: Hamiltonian Tours}. 
\begin{quote}
INPUT: A graph $G=(V,E)$. \\
DECIDE: Is there a path that visits every vertex exactly once and
returns to its starting point?
\end{quote}

No one knows how to solve this problem in polynomial time.  The subtle
distinction between visiting edges and visiting vertices changes an
easy problem into a hard one.

{\bf Easy: 2-dimensional Matching}.
\begin{quote}
INPUT: A graph $G=(V,E)$. \\
DECIDE: Does there exist a perfect pairing (matching) of vertices: a
set of $|V|/2$ edges that touch each vertex exactly once?
\end{quote}

We can think of this problem as follows: each vertex represents a
person at a fair.  There's an edge between two people if they are
willing to sit next to each other on the Ferris wheel.  Is there a way
to pair up people so that everyone rides on the Ferris wheel exactly
once, and every seat on the Ferris wheel contains two people? 

It turns out that this problem is solvable in polynomial time.  We
won't go into the algorithm here; the high level idea is that we start
from some matching in which not every vertex is matched, and we
successively improve it by matching two more vertices until we can
improve it no longer.

{\bf Hard: 3-dimensional Matching}. \\
However, when the Ferris wheel seats allow three persons instead of
two, the problem becomes hard.
\begin{quote}
INPUT: A set of vertices, and a set of allowable triples of vertices.
See Figure \ref{fig:3dm}.\\
DECIDE: Does There exists a set of disjoint triples covering all
vertices?
\end{quote}

\begin{figure}[h]
\centerline{\mbox{\psfig{figure=3dm-fig.ps,height=1in}}}
\caption{A 3-dimensional matching problem}
\label{fig:3dm}
\end{figure}


{\bf Easy: Multiplication}.
\begin{quote}
INPUT: Integers $x,y$. \\
OUTPUT: The product $x \cdot y$.
\end{quote}

{\bf Hard: Un-multiplying (factoring)}.
\begin{quote}
INPUT: Integer $n$. \\
OUTPUT: If $n$ is not prime, output two integers $x, y$ such that $1 <
x,y < n$ and $xy = n$.
\end{quote}

Again, the problem of factoring is not known to be in $\poly$.  In
this case, the hardness of a problem turns out to be useful.  Some
cryptographic algorithms depend on the assumption that factoring is
hard to ensure that a code cannot be broken by a computer.

{\bf Easy: Formula evaluation.}
\begin{quote}
INPUT: A boolean formula (e.g.\ $(x \vee y \bar z) \wedge (z \vee \bar x)$)
and a value for all variables in the formula (e.g.\ $x = 0, y = 1, z =
0$). \\
OUTPUT: The value of the formula given the variable settings (e.g.\ 1,
or ``true'' in this case).
\end{quote}

It's not too hard to think of what the algorithm would be in this
case. All we would have to do is to substitute the values in for the
various variables, then simplify the formula to a single value in
multiple passes (e.g.\ in a pass simplify $1 \vee 0$ to 1).

{\bf Hard: Satisfiability of boolean formula}.
\begin{quote}
INPUT: A boolean formula. \\
DECIDE: Do there exist values for all variables that would make the
formula true?
\end{quote}

Given that there are $n$ different variables in the formula, there are
$2^n$ possible assignments of 0/1 to the variables.  This gives us an
easy exponentional time algorithm: simply try all possible
assignments.  No one knows if there is a way to be cleverer, and cut
the running time down to polynomial.

{\bf Hard(er): Tautology}.
\begin{quote}
INPUT: A boolean formula. \\
DECIDE: Do all possible assignments of values to variables make the
formula true?
\end{quote}

It turns out that this problem seems to be even harder than the
Satisfiability problem.

{\bf Easy: NIM}.
\begin{quote}
INPUT: Some piles of rocks. \\
DECIDE: Is this a winning position for the first player in a game of
NIM?
\end{quote}

It turns out that in some configurations, the first player (if the
player knows what he or she is doing) can always win, no matter what
the second player does.  The rules of NIM are as follows: (1) On a
player's move, the player can take any number of stones from some
(only one) pile of rocks; (2) the player who takes the last stone
wins.  There is a nice algorithm that solves this problem in
polynomial time.

{\bf Hard: Generalized Geography}. \\

Recall the game of Geography: a player starts with the name of some
country (``Algeria'').  The second player has to come up with a
different name that starts with the letter that ends the first name
(``Afghanistan'').  The first player now has to come up with a country
that starts with the letter that ended the second player's country
(``Nepal'').  And so on.  The game ends when some player can't think
of a country that would obey the rule.  

The game can be generalized to a directed graph in which the vertices
stand for countries, and an edge is directed from vertex $i$ to
vertex $j$, if saying country $j$ after country $i$ is a legal move.
So the objective is to force the other player onto a vertex that has
no edges coming out of it.



\begin{quote}
INPUT: A directed graph, and a start vertex. See Figure \ref{fig:gg}.
\\
DECIDE: Can the first player force a win; e.g.\ can the first player
win no matter what the second player does?
\end{quote}

\begin{figure}[t]
\centerline{\mbox{\psfig{figure=gg-fig.ps,height=1in}}}
\caption{Generalized Geography}
\label{fig:gg}
\end{figure}

This problem seems nastier than all the other problems that we have
considered so far.  The alternation of the players' moves makes it
very difficult to solve.

\section{Overview}

Right now, we have to be content with saying that we {\it think} that
the hard problems are not in $\poly$.  Theoretical computer science
has yet to come up with the tools to prove that problems of these
sorts are not in $\poly$.  We do not yet have the equivalent of the
pumping lemma or diagonalization to prove that certain problems cannot
be solved efficiently in the same way that we could prove that certain
languages were not regular or not decidable.

We can show, however, that there are some problems, even decidable
problems, which are not solvable in polynomial time.  Our first
example of this is the Time Bounded Halting Problem.  (The rest of the
lecture covered the Time Bounded Halting Problem, which is covered in
Handout~33, starting on page 8).

\end{document}
