Finished last two sections
This commit is contained in:
		@@ -23,9 +23,7 @@
 | 
				
			|||||||
	\input{parts/02 residual}
 | 
						\input{parts/02 residual}
 | 
				
			||||||
	\input{parts/03 fulkerson}
 | 
						\input{parts/03 fulkerson}
 | 
				
			||||||
	\input{parts/04 applications}
 | 
						\input{parts/04 applications}
 | 
				
			||||||
 | 
						\input{parts/05 reductions}
 | 
				
			||||||
 | 
						\input{parts/06 bonus}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
\end{document}
 | 
					\end{document}
 | 
				
			||||||
							
								
								
									
										131
									
								
								Advanced/Graph Algorithms/parts/05 reductions.tex
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										131
									
								
								Advanced/Graph Algorithms/parts/05 reductions.tex
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,131 @@
 | 
				
			|||||||
 | 
					\section{Reductions}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\definition{Independent Sets}
 | 
				
			||||||
 | 
					An \textit{independent set} is a set of vertices\footnotemark{} in which no two are connected. $\{B, C, D, E\}$ form an independent set in the following graph:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\footnotetext{\say{Node} and \say{Vertex} are synonyms in graph theory.}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{center}
 | 
				
			||||||
 | 
						\begin{tikzpicture}[
 | 
				
			||||||
 | 
							node distance = 12mm,
 | 
				
			||||||
 | 
							hatch/.style = {
 | 
				
			||||||
 | 
								pattern=north west lines,
 | 
				
			||||||
 | 
								pattern color=gray
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
							% Nodes
 | 
				
			||||||
 | 
							\begin{scope}[layer = nodes]
 | 
				
			||||||
 | 
								\node[main] (A) {$A$};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								% Patterns are transparent.
 | 
				
			||||||
 | 
								% Fill nodes first so paths don't show through
 | 
				
			||||||
 | 
								\node[main, draw = white] (B1) [above left of = A] {$\phantom{B}$};
 | 
				
			||||||
 | 
								\node[main, draw = white] (C1) [below left of = A] {$\phantom{C}$};
 | 
				
			||||||
 | 
								\node[main, draw = white] (D1) [below right of = A] {$\phantom{D}$};
 | 
				
			||||||
 | 
								\node[main, draw = white] (E1) [above right of = A] {$\phantom{E}$};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								\node[main, hatch] (B) [above left of = A] {$B$};
 | 
				
			||||||
 | 
								\node[main, hatch] (C) [below left of = A] {$C$};
 | 
				
			||||||
 | 
								\node[main, hatch] (D) [below right of = A] {$D$};
 | 
				
			||||||
 | 
								\node[main, hatch] (E) [above right of = A] {$E$};
 | 
				
			||||||
 | 
							\end{scope}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Edges
 | 
				
			||||||
 | 
							\draw
 | 
				
			||||||
 | 
								(A) edge (B)
 | 
				
			||||||
 | 
								(A) edge (C)
 | 
				
			||||||
 | 
								(A) edge (D)
 | 
				
			||||||
 | 
								(A) edge (E)
 | 
				
			||||||
 | 
							;
 | 
				
			||||||
 | 
						\end{tikzpicture}
 | 
				
			||||||
 | 
					\end{center}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\definition{Vertex Covers}
 | 
				
			||||||
 | 
					A \textit{vertex cover} is a set of vertices that includes at least one endpoint of each edge. $B$ and $D$ form a vertex cover of the following graph:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{center}
 | 
				
			||||||
 | 
						\begin{tikzpicture}[
 | 
				
			||||||
 | 
							node distance = 12mm,
 | 
				
			||||||
 | 
							hatch/.style = {
 | 
				
			||||||
 | 
								pattern=north west lines,
 | 
				
			||||||
 | 
								pattern color=gray
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
							% Nodes
 | 
				
			||||||
 | 
							\begin{scope}[layer = nodes]
 | 
				
			||||||
 | 
								\node[main] (A) {$A$};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								% Patterns are transparent.
 | 
				
			||||||
 | 
								% Fill nodes first so paths don't show through
 | 
				
			||||||
 | 
								\node[main, draw = white] (B1) [right of = A] {$\phantom{B}$};
 | 
				
			||||||
 | 
								\node[main, hatch] (B) [right of = A] {$B$};
 | 
				
			||||||
 | 
								\node[main, draw = white] (D1) [below of = B] {$\phantom{D}$};
 | 
				
			||||||
 | 
								\node[main, hatch] (D) [below of = B] {$D$};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								\node[main] (C) [right of = B] {$C$};
 | 
				
			||||||
 | 
								\node[main] (E) [right of = D] {$E$};
 | 
				
			||||||
 | 
							\end{scope}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Edges
 | 
				
			||||||
 | 
							\draw
 | 
				
			||||||
 | 
								(A) edge (B)
 | 
				
			||||||
 | 
								(B) edge (C)
 | 
				
			||||||
 | 
								(B) edge (D)
 | 
				
			||||||
 | 
								(D) edge (E)
 | 
				
			||||||
 | 
							;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Flow
 | 
				
			||||||
 | 
							\draw[path]
 | 
				
			||||||
 | 
								(B) -- (A)
 | 
				
			||||||
 | 
								(B) -- (C)
 | 
				
			||||||
 | 
								(B) -- (D)
 | 
				
			||||||
 | 
								(D) -- (E)
 | 
				
			||||||
 | 
							;
 | 
				
			||||||
 | 
						\end{tikzpicture}
 | 
				
			||||||
 | 
					\end{center}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vfill
 | 
				
			||||||
 | 
					\pagebreak
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\problem{}<IndepCover>
 | 
				
			||||||
 | 
					Let $G$ be a graph with a set of vertices $V$. \\
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Show that $S \subset V$ is an independent set iff $(V - S)$ is a vertex cover. \\
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\hint{$(V - S)$ is the set of elements in $V$ that are not in $S$.}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{solution}
 | 
				
			||||||
 | 
						Suppose $S$ is an independent set.
 | 
				
			||||||
 | 
						\begin{itemize}
 | 
				
			||||||
 | 
							\item [$\implies$] All edges are in $(V - S)$ or connect $(V - S)$ and $S$.
 | 
				
			||||||
 | 
							\item [$\implies$] $(V - S)$ is a vertex cover.
 | 
				
			||||||
 | 
						\end{itemize}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						\linehack{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Suppose $S$ is a vertex cover.
 | 
				
			||||||
 | 
						\begin{itemize}
 | 
				
			||||||
 | 
							\item [$\implies$] There are no edges with both endpoints in $(V - S)$.
 | 
				
			||||||
 | 
							\item [$\implies$] $(V - S)$ is an independent set.
 | 
				
			||||||
 | 
						\end{itemize}
 | 
				
			||||||
 | 
					\end{solution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vfill
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\problem{}
 | 
				
			||||||
 | 
					Consider the following two problems:
 | 
				
			||||||
 | 
					\begin{itemize}
 | 
				
			||||||
 | 
						\item Given a graph $G$, determine if it has an independent set of size $\geq k$.
 | 
				
			||||||
 | 
						\item Given a graph $G$, determine if it has a vertex cover of size $\leq k$.
 | 
				
			||||||
 | 
					\end{itemize}
 | 
				
			||||||
 | 
					Show that these are equivalent. In other words, show that an algorithm that solves one can be used to solve the other.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{solution}
 | 
				
			||||||
 | 
						This is a direct consequence of \ref{IndepCover}. You'll need to show that the size constraints are satisfied, but that's fairly easy to do.
 | 
				
			||||||
 | 
					\end{solution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vfill
 | 
				
			||||||
 | 
					\pagebreak
 | 
				
			||||||
							
								
								
									
										200
									
								
								Advanced/Graph Algorithms/parts/06 bonus.tex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										200
									
								
								Advanced/Graph Algorithms/parts/06 bonus.tex
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,200 @@
 | 
				
			|||||||
 | 
					\section{Crosses (Bonus Problem)}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You are given an $n \times n$ grid. Some of its squares are white, and some are gray. Your goal is to place $n$ crosses on white cells so that each row and each column contains exactly one cross.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vspace{2ex}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Here is an example of such a grid, including a possible solution.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\newcommand{\bx}[2]{
 | 
				
			||||||
 | 
						\draw[
 | 
				
			||||||
 | 
							line width = 1.5mm
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
							(#1 + 0.3, #2 + 0.3) -- (#1 + 0.7, #2 + 0.7)
 | 
				
			||||||
 | 
							(#1 + 0.7, #2 + 0.3) -- (#1 + 0.3, #2 + 0.7);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\newcommand{\dk}[2]{
 | 
				
			||||||
 | 
						\draw[
 | 
				
			||||||
 | 
							line width = 0mm,
 | 
				
			||||||
 | 
							fill = gray
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
							(#1, #2) --
 | 
				
			||||||
 | 
							(#1 + 1, #2) --
 | 
				
			||||||
 | 
							(#1 + 1, #2 + 1) --
 | 
				
			||||||
 | 
							(#1, #2 + 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{center}
 | 
				
			||||||
 | 
					\begin{tikzpicture}[
 | 
				
			||||||
 | 
						scale = 0.8
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Dark squares
 | 
				
			||||||
 | 
							\dk{0}{2}
 | 
				
			||||||
 | 
							\dk{1}{0}
 | 
				
			||||||
 | 
							\dk{1}{1}
 | 
				
			||||||
 | 
							\dk{1}{2}
 | 
				
			||||||
 | 
							\dk{1}{4}
 | 
				
			||||||
 | 
							\dk{2}{2}
 | 
				
			||||||
 | 
							\dk{2}{4}
 | 
				
			||||||
 | 
							\dk{3}{0}
 | 
				
			||||||
 | 
							\dk{3}{1}
 | 
				
			||||||
 | 
							\dk{3}{3}
 | 
				
			||||||
 | 
							\dk{3}{4}
 | 
				
			||||||
 | 
							\dk{4}{3}
 | 
				
			||||||
 | 
							\dk{4}{1}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Base grid
 | 
				
			||||||
 | 
							\foreach \x in {0,...,5} {
 | 
				
			||||||
 | 
								\draw[line width = 0.4mm]
 | 
				
			||||||
 | 
									(0, \x) -- (5, \x)
 | 
				
			||||||
 | 
									(\x, 0) -- (\x, 5);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% X marks
 | 
				
			||||||
 | 
							\bx{0}{4}
 | 
				
			||||||
 | 
							\bx{1}{3}
 | 
				
			||||||
 | 
							\bx{2}{1}
 | 
				
			||||||
 | 
							\bx{3}{2}
 | 
				
			||||||
 | 
							\bx{4}{0}
 | 
				
			||||||
 | 
					\end{tikzpicture}
 | 
				
			||||||
 | 
					\end{center}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\problem{}
 | 
				
			||||||
 | 
					Find a solution for the following grid.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{center}
 | 
				
			||||||
 | 
					\begin{tikzpicture}[
 | 
				
			||||||
 | 
						scale = 1
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
						% Dark squares
 | 
				
			||||||
 | 
						\dk{0}{2}
 | 
				
			||||||
 | 
						\dk{0}{3}
 | 
				
			||||||
 | 
						\dk{0}{6}
 | 
				
			||||||
 | 
						\dk{0}{7}
 | 
				
			||||||
 | 
						\dk{1}{0}
 | 
				
			||||||
 | 
						\dk{1}{1}
 | 
				
			||||||
 | 
						\dk{1}{4}
 | 
				
			||||||
 | 
						\dk{1}{5}
 | 
				
			||||||
 | 
						\dk{1}{6}
 | 
				
			||||||
 | 
						\dk{1}{7}
 | 
				
			||||||
 | 
						\dk{2}{0}
 | 
				
			||||||
 | 
						\dk{2}{1}
 | 
				
			||||||
 | 
						\dk{2}{3}
 | 
				
			||||||
 | 
						\dk{2}{4}
 | 
				
			||||||
 | 
						\dk{2}{5}
 | 
				
			||||||
 | 
						\dk{2}{6}
 | 
				
			||||||
 | 
						\dk{2}{7}
 | 
				
			||||||
 | 
						\dk{3}{1}
 | 
				
			||||||
 | 
						\dk{3}{2}
 | 
				
			||||||
 | 
						\dk{3}{3}
 | 
				
			||||||
 | 
						\dk{3}{4}
 | 
				
			||||||
 | 
						\dk{3}{5}
 | 
				
			||||||
 | 
						\dk{3}{6}
 | 
				
			||||||
 | 
						\dk{4}{0}
 | 
				
			||||||
 | 
						\dk{4}{1}
 | 
				
			||||||
 | 
						\dk{4}{2}
 | 
				
			||||||
 | 
						\dk{4}{3}
 | 
				
			||||||
 | 
						\dk{4}{6}
 | 
				
			||||||
 | 
						\dk{5}{1}
 | 
				
			||||||
 | 
						\dk{5}{4}
 | 
				
			||||||
 | 
						\dk{5}{5}
 | 
				
			||||||
 | 
						\dk{5}{6}
 | 
				
			||||||
 | 
						\dk{6}{0}
 | 
				
			||||||
 | 
						\dk{6}{1}
 | 
				
			||||||
 | 
						\dk{6}{2}
 | 
				
			||||||
 | 
						\dk{6}{3}
 | 
				
			||||||
 | 
						\dk{6}{4}
 | 
				
			||||||
 | 
						\dk{6}{5}
 | 
				
			||||||
 | 
						\dk{7}{0}
 | 
				
			||||||
 | 
						\dk{7}{4}
 | 
				
			||||||
 | 
						\dk{7}{6}
 | 
				
			||||||
 | 
						\dk{7}{7}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						% Base grid
 | 
				
			||||||
 | 
						\foreach \x in {0,...,8} {
 | 
				
			||||||
 | 
							\draw[line width = 0.4mm]
 | 
				
			||||||
 | 
								(0, \x) -- (8, \x)
 | 
				
			||||||
 | 
								(\x, 0) -- (\x, 8);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					\end{tikzpicture}
 | 
				
			||||||
 | 
					\end{center}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\pagebreak
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\begin{solution}
 | 
				
			||||||
 | 
						\begin{center}
 | 
				
			||||||
 | 
						\begin{tikzpicture}[
 | 
				
			||||||
 | 
							scale = 0.6
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
							% Dark squares
 | 
				
			||||||
 | 
							\dk{0}{2}
 | 
				
			||||||
 | 
							\dk{0}{3}
 | 
				
			||||||
 | 
							\dk{0}{6}
 | 
				
			||||||
 | 
							\dk{0}{7}
 | 
				
			||||||
 | 
							\dk{1}{0}
 | 
				
			||||||
 | 
							\dk{1}{1}
 | 
				
			||||||
 | 
							\dk{1}{4}
 | 
				
			||||||
 | 
							\dk{1}{5}
 | 
				
			||||||
 | 
							\dk{1}{6}
 | 
				
			||||||
 | 
							\dk{1}{7}
 | 
				
			||||||
 | 
							\dk{2}{0}
 | 
				
			||||||
 | 
							\dk{2}{1}
 | 
				
			||||||
 | 
							\dk{2}{3}
 | 
				
			||||||
 | 
							\dk{2}{4}
 | 
				
			||||||
 | 
							\dk{2}{5}
 | 
				
			||||||
 | 
							\dk{2}{6}
 | 
				
			||||||
 | 
							\dk{2}{7}
 | 
				
			||||||
 | 
							\dk{3}{1}
 | 
				
			||||||
 | 
							\dk{3}{2}
 | 
				
			||||||
 | 
							\dk{3}{3}
 | 
				
			||||||
 | 
							\dk{3}{4}
 | 
				
			||||||
 | 
							\dk{3}{5}
 | 
				
			||||||
 | 
							\dk{3}{6}
 | 
				
			||||||
 | 
							\dk{4}{0}
 | 
				
			||||||
 | 
							\dk{4}{1}
 | 
				
			||||||
 | 
							\dk{4}{2}
 | 
				
			||||||
 | 
							\dk{4}{3}
 | 
				
			||||||
 | 
							\dk{4}{6}
 | 
				
			||||||
 | 
							\dk{5}{1}
 | 
				
			||||||
 | 
							\dk{5}{4}
 | 
				
			||||||
 | 
							\dk{5}{5}
 | 
				
			||||||
 | 
							\dk{5}{6}
 | 
				
			||||||
 | 
							\dk{6}{0}
 | 
				
			||||||
 | 
							\dk{6}{1}
 | 
				
			||||||
 | 
							\dk{6}{2}
 | 
				
			||||||
 | 
							\dk{6}{3}
 | 
				
			||||||
 | 
							\dk{6}{4}
 | 
				
			||||||
 | 
							\dk{6}{5}
 | 
				
			||||||
 | 
							\dk{7}{0}
 | 
				
			||||||
 | 
							\dk{7}{4}
 | 
				
			||||||
 | 
							\dk{7}{6}
 | 
				
			||||||
 | 
							\dk{7}{7}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% Base grid
 | 
				
			||||||
 | 
							\foreach \x in {0,...,8} {
 | 
				
			||||||
 | 
								\draw[line width = 0.4mm]
 | 
				
			||||||
 | 
									(0, \x) -- (8, \x)
 | 
				
			||||||
 | 
									(\x, 0) -- (\x, 8);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							% X marks
 | 
				
			||||||
 | 
							\bx{0}{5}
 | 
				
			||||||
 | 
							\bx{1}{3}
 | 
				
			||||||
 | 
							\bx{2}{2}
 | 
				
			||||||
 | 
							\bx{3}{7}
 | 
				
			||||||
 | 
							\bx{4}{4}
 | 
				
			||||||
 | 
							\bx{5}{0}
 | 
				
			||||||
 | 
							\bx{6}{6}
 | 
				
			||||||
 | 
							\bx{7}{1}
 | 
				
			||||||
 | 
						\end{tikzpicture}
 | 
				
			||||||
 | 
						\end{center}
 | 
				
			||||||
 | 
					\end{solution}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\problem{}
 | 
				
			||||||
 | 
					Turn this into a network flow problem.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					\vfill
 | 
				
			||||||
 | 
					\pagebreak
 | 
				
			||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
\usetikzlibrary{arrows.meta}
 | 
					\usetikzlibrary{arrows.meta}
 | 
				
			||||||
\usetikzlibrary{shapes.geometric}
 | 
					\usetikzlibrary{shapes.geometric}
 | 
				
			||||||
 | 
					\usetikzlibrary{patterns}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
% We put nodes in a separate layer, so we can
 | 
					% We put nodes in a separate layer, so we can
 | 
				
			||||||
% slightly overlap with paths for a perfect fit
 | 
					% slightly overlap with paths for a perfect fit
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user