\documentclass{article}

\usepackage[noend]{algpseudocode}
\usepackage[margin=1in]{geometry}
\usepackage{enumitem}
\usepackage{cprotect}
\usepackage{listings}
\usepackage{wrapfig}

\setlength{\headsep}{0.5 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{4pt}
\addtolength\topmargin{-1cm}
\textheight  9.25in

\usepackage{amsmath,amsfonts,graphicx,multicol, color}
\usepackage[normalem]{ulem}

\newcommand{\todo}{\textcolor{red}}
\newcommand{\red}{\textcolor{red}}

\usepackage{url}

%\def\IsSolution{1}   % Uncomment to debug solutions. Note: Makefile generates both discussion and solution automatically.

%
% Define two macros
%   \soln{}     --- contents appear only in solution
%   \notsoln{}  --- contents appear only if not solution

\usepackage{etoolbox}
\ifx\IsSolution\undefined
 \newcommand{\notsoln}[1]{#1}
 \newcommand{\soln}[1]{}
 \newcommand{\thesoln}[1]{}
\else
  \newcommand{\notsoln}[1]{}
  \newcommand{\soln}[1]{#1}
  \newcommand{\thesoln}[1]{{\color{red}\textbf{Solution:} #1}}
\fi


%
% The following macro is used to generate the header.
%
\newcommand{\header}[1]{
   \pagestyle{myheadings}
   \thispagestyle{plain}
   \newpage
   \setcounter{page}{1}
   \noindent
   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 6.28in { {\bf COMPSCI 311: Introduction to Algorithms
		\hfill Fall 2019} }
       \vspace{4mm}
       \hbox to 6.28in { {\Large \hfill Homework #1 \soln{Solutions} \hfill } }
       \vspace{2mm}
       \hbox to 6.28in { Released 11/23/2019 \hfill Due 12/11/2019 11:59pm in Gradescope}
      \vspace{2mm}}
   }
   \end{center}
   \markboth{Homework #1}{Homework #1}

   \vspace*{4mm}
}

\newcounter{problem}
\newcommand{\prob}{\addtocounter{problem}{1}\noindent {\bf Problem \theproblem.} ~}

\begin{document}
\header{6}

\textbf{Instructions.} You may work in groups, but you must write solutions yourself.
List collaborators on your submission.   Also list any sources of help (including online
sources) other than the textbook and course staff.

If you are asked to design an algorithm, please provide: (a) the pseudocode or precise description in words of the algorithm, (b) an explanation of the intuition for the algorithm, (c) a proof of correctness, (d) the running time of your algorithm and (e) justification for your running time analysis. 

This homework has 110 points, but the A level will be no higher than 90, so you may think of any ten of the
points as extra credit if you like.

\textbf{Submissions.} Please submit a PDF file. You may submit a scanned handwritten document, but a typed submission is preferred. Please assign pages to questions in Gradescope.

1. \textbf{(20 points) Use All Letters}
Consider a game where you are given a set of tiles, each with a printed letter, and you have to arrange them to make words, much like in Scrabble.
It may be easy to make \emph{some} words, but becomes much harder if you have to use \emph{all} given letters.

More precisely, given a \emph{multiset} of symbols (letters) $L$ from an alphabet $\Sigma$ (thus, the same letter may appear in $L$ multiple times), and a set of words $W \subseteq \Sigma^*$, \textsc{UseAllLetters} asks if it is possible to use all letters from $L$ to make words belonging to $W$. You may form the same word multiple times (so if you have $g$ and $d$ twice, and four $o$'s, you might spell \emph{good} twice if it is in $W$). Prove that \textsc{UseAllLetters} is NP-complete.

2. \textbf{(20 points) The Last Token}
Consider the following game played on a graph $G$ where each node can hold an arbitrary number of tokens. A move consists of removing two tokens from one node (that has at least two tokens) and adding \emph{one} token to some neighboring node. The \textsc{LastToken} problem asks whether, given a graph $G$ and an initial number of tokens $0 \le t(v) \le n^2$ for each vertex $v$, there is a sequence of moves that results in only one
token being left in $G$. Prove that \textsc{LastToken} is NP-complete. 

3. \textbf{(20 points) Intersection Inference} (K\&T Exercise 8.16)

4. \textbf{(20 points) Independent Set}  (K\&T Exercise 8.22)

5. \textbf{(30 points) Triangle-TSP}
Recall that the input to the TSP problem is a function $d$, where $d(x, y)$
is the distance from node $x$ to node $y$.  We require that $d(x, x) = 0$ and
that $d(x, y) > 0$ if $x  \ne y$.

Such a distance function is said to obey the \emph{triangle inequality} if $d(x, z) \le d(x, y) + d(y, z)$ for
any three nodes $x$, $y$, and $z$.  The \textsc{TriangleTSP}
problem is the special case of TSP where the distance function satisfies the
triangle inequality, so it is $\{ (d, k)$: $d$ satisfies the triangle inequality
and there is a tour of all the cities with total distance at most $k\}$.

(a) Prove that \textsc{TriangleTSP} is NP-complete.  (Hint: Look at the reduction in
lecture from HAM-Circuit to ordinary TSP.)

(b) The \emph{2-Approximate TSP} problem is to input a distance function $d$ and output
a tour of the cities that has total distance at most twice that of the optimal tour.

Prove that the 2-Approximate TSP problem is NP-hard, meaning that if there
were a polynomial-time algorithm for it, P would equal NP.  (The most natural
way to prove this is to use such an algorithm to solve the NP-complete
Hamiltonian cycle problem.)

(c) If your solution to (b) was correct, the distance function you constructed
did \emph{not} satisfy the triangle inequality.  We know that because for symmetric distances, the 2-Approximate \textsc{TriangleTSP} problem is in P, and we don't believe that you proved P equals NP).  Prove that 2-Approximate \textsc{TriangleTSP} is in P, assuming the distance function is symmetric.  (Hint: Consider a minimum
spanning tree for the weighted graph that has all possible edges, with each edge
weighted according to $d$.)

6. \textbf{(0 points).} How long did it take you to complete this assignment?

\end{document}
