diff --git a/Intermediate/An Introduction to Graph Theory/bridges.png b/Intermediate/An Introduction to Graph Theory/bridges.png deleted file mode 100755 index fc621b0..0000000 Binary files a/Intermediate/An Introduction to Graph Theory/bridges.png and /dev/null differ diff --git a/Intermediate/An Introduction to Graph Theory/graphs.png b/Intermediate/An Introduction to Graph Theory/graphs.png deleted file mode 100755 index d674b0e..0000000 Binary files a/Intermediate/An Introduction to Graph Theory/graphs.png and /dev/null differ diff --git a/Intermediate/An Introduction to Graph Theory/hypercube.png b/Intermediate/An Introduction to Graph Theory/hypercube.png deleted file mode 100755 index 7e9581e..0000000 Binary files a/Intermediate/An Introduction to Graph Theory/hypercube.png and /dev/null differ diff --git a/Intermediate/An Introduction to Graph Theory/main.tex b/Intermediate/An Introduction to Graph Theory/main.tex index 46cf988..1a32a71 100755 --- a/Intermediate/An Introduction to Graph Theory/main.tex +++ b/Intermediate/An Introduction to Graph Theory/main.tex @@ -1,12 +1,13 @@ % use [nosolutions] flag to hide solutions. % use [solutions] flag to show solutions. \documentclass[ - solutions + solutions, + singlenumbering ]{../../resources/ormc_handout} -\usepackage{tkz-graph} - +\input{tikxset.tex} +\usepackage{adjustbox} \uptitlel{Intermediate 2} \uptitler{ORMC Summer Sessions} @@ -20,693 +21,9 @@ \maketitle - \section{Graphs} - A \textit{graph} is a collection of nodes (vertices) and connections between them (edges). If an edge $e$ connects the vertices $v_i$ and $v_j$, then we write $e = {v_i, v_j}$. An example is below. + \input{parts/0 intro.tex} + \input{parts/1 paths.tex} - \begin{center} - \begin{tikzpicture} [scale = .6] \label{pic:1} - \SetGraphUnit{5} - \Vertex{B} - \WE(B){A} - \EA(B){C} - \Edge(B)(A) - \Edge(C)(B) - \tikzset{EdgeStyle/.append style = {bend left = 50}} - \Edge(A)(C) - \Edge(C)(A) - \coordinate [label=above:{$e_1$}] (e1) at (-2.1,.0); - \coordinate [label=above:{$e_2$}] (e2) at (0,2.45); - \coordinate [label=below:{$e_3$}] (e3) at (0,-2.5); - \coordinate [label=above:{$e_4$}] (e4) at (2.1,.0); - \end{tikzpicture} - \end{center} - - More formally, a graph is defined by a set of vertices $\{v_1, v_2, ...\}$, and a set of edges $\{\ \{v_1, v_2\}, \{v_1, v_3\}, ...\ \}$. - - \medskip - - If the order of the vertices in an edge does not matter, - a graph is called {\it undirected}. A graph is called - a {\it directed graph} if the order of the vertices does matter. - For example, the (undirected) graph above - has three vertices, $A$, $B$, and $C$, and four edges, - $e_1 =\{A,B\}$, $e_2 = \{A,C\}$, $e_3 = \{A,C\}$, - and $e_4 = \{B,C\}$. - - \problem{} - Draw an undirected graph that has the vertices - $A$, $B$, $C$, $D$, and $E$ and the edges - $\{A,B\}$, $\{A,C\}$, $\{A,D\}$, $\{A,E\}$, - $\{B,C\}$, $\{C,D\}$, and $\{D,E\}$ in the space below. - \vfill - - - Graphs are useful for solving many different kinds of problems. Most situations that involve some kind of ``relation'' between elements can be represented by a graph. \\ - - \medskip - - Also, note that the graphs we're discussing today have very little in common with the ``graphs'' of functions you're used to seeing in your math classes. - - \pagebreak - - - Graphs are fully defined by their vertices and edges. The exact position of each vertex and edge doesn't matter---only which nodes are connected to each other. As such,two equivalent graphs can look very different. - - \problem{} - Prove that the graphs below are equivalent by comparing - the sets of their vertices and edges. - - \begin{center} - \tikzset{EdgeStyle/.append style = {-}} - \begin{tikzpicture} [scale = .8] - \SetGraphUnit{3.5} - \draw [color = white] (0,0) -- (0,-5); - \Vertex{A} - \EA(A){B} - \SO(B){C} - \SO(A){D} - \Edge(A)(B) - \Edge(A)(C) - \Edge(A)(D) - \Edge(B)(C) - \Edge(B)(D) - \Edge(C)(D) - \end{tikzpicture} \hspace{70pt} - \begin{tikzpicture} [scale = .8] - \tikzset{EdgeStyle/.append style = {-}} - \SetGraphUnit{3} - \Vertex{A} - \SOWE(A){B} - \SOEA(A){C} - \SO(A){D} - \Edge(A)(B) - \Edge(A)(C) - \Edge(A)(D) - \Edge(B)(D) - \Edge(C)(D) - \tikzset{EdgeStyle/.append style = {bend right = 70}} - \Edge(B)(C) - \end{tikzpicture} - \end{center} - - \vfill - \pagebreak - - \definition{} - The degree $D(v)$ of a vertex $v$ of a graph - is the number of the edges of the graph - connected to that vertex. - - \theorem{} - For any graph, the sum of the degrees of the vertices - equals twice the number of the edges. - - \problem{} - Prove \ref{sum_degrees} - \vfill - - \problem{} - Prove the following corollary of \ref{sum_degrees}: \\ - The number of vertices of odd degree in any graph - is even. - \vfill - \pagebreak - - - \problem{} - One girl tells another, ``There are 25 kids - in my class. Isn't it funny that each of them - has 5 friends in the class?'' ``This cannot be true,'' - immediately replies the other girl. - How did she know? - - \problempart{} - Let us represent the children - in the first girl's class - as vertices of a graph. - Let us represent the friendships - as the graph's edges. - What is the degree of each vertex? - \vfill - - \problempart{} - So how did the second girl know - right away? - \vfill - \pagebreak - - \section{Paths and cycles} - - A \textit{path} in a graph is, intuitively, a sequence of edges: $\{\ \{x_1, x_2\}, \{x_2, x_4\}, ...\ \}$. For example, I've highlighted one possible path in the graph below. - - \begin{center} - \begin{tikzpicture}[ - node distance={15mm}, - thick, - main/.style = {draw, circle} - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [above right of=1] {$x_2$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - \node[main] (5) [above right of=4] {$x_5$}; - \node[main] (6) [below right of=4] {$x_6$}; - \node[main] (7) [below right of=5] {$x_7$}; - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (2) -- (5); - \draw[-] (2) -- (4); - \draw[-] (3) -- (6); - \draw[-] (3) -- (4); - \draw[-] (4) -- (5); - \draw[-] (5) -- (7); - \draw[-] (6) -- (7); - - \draw [ - line width=2mm, - draw=black, - opacity=0.4 - ] (1) -- (2) -- (4) -- (3) -- (6); - \end{tikzpicture} - \end{center} - - A \textit{cycle} is a path that starts and ends on the same vertex: - - \begin{center} - \begin{tikzpicture}[ - node distance={15mm}, - thick, - main/.style = {draw, circle} - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [above right of=1] {$x_2$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - \node[main] (5) [above right of=4] {$x_5$}; - \node[main] (6) [below right of=4] {$x_6$}; - \node[main] (7) [below right of=5] {$x_7$}; - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (2) -- (5); - \draw[-] (2) -- (4); - \draw[-] (3) -- (6); - \draw[-] (3) -- (4); - \draw[-] (4) -- (5); - \draw[-] (5) -- (7); - \draw[-] (6) -- (7); - - \draw [ - line width=2mm, - draw=black, - opacity=0.4 - ] (2) -- (4) -- (3) -- (6) -- (7) -- (5) -- (2); - \end{tikzpicture} - \end{center} - - - A \textit{Eulerian\footnotemark} path is a path that traverses each edge exactly once. \\ - \footnotetext{Pronounced ``oiler''. These terms are named after a great Swiss mathematician, Leonhard Euler (1707-1783), considered by many as the founder of graph theory.} - A Eulerian cycle is a cycle that does the same. - - \medskip - - Similarly, a {\it Hamiltonian} path is a path in a graph that visits each vertex exactly once, \\ - and a Hamiltonian cycle is a closed Hamiltonian path. - - \medskip - - An example of a Hamiltonian path is below. - - \begin{center} - \begin{tikzpicture}[ - node distance={15mm}, - thick, - main/.style = {draw, circle} - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [above right of=1] {$x_2$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - \node[main] (5) [above right of=4] {$x_5$}; - \node[main] (6) [below right of=4] {$x_6$}; - \node[main] (7) [below right of=5] {$x_7$}; - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (2) -- (5); - \draw[-] (2) -- (4); - \draw[-] (3) -- (6); - \draw[-] (3) -- (4); - \draw[-] (4) -- (5); - \draw[-] (5) -- (7); - \draw[-] (6) -- (7); - - \draw [ - line width=2mm, - draw=black, - opacity=0.4 - ] (1) -- (2) -- (4) -- (3) -- (6) -- (7) -- (5); - \end{tikzpicture} - \end{center} - - \vfill - \pagebreak - - - \definition{} - We say a graph is \textit{connected} - if there is a path between every pair - of its vertices. A graph is called - \textit{disconnected} otherwise. - - \problem{} - Draw a disconnected graph with four vertices. \\ - Then, draw a graph with four vertices, - all of degree one. - \vfill - - \problem{} - Find a Hamiltonian cycle in the following graph. - - \begin{center} - \begin{tikzpicture}[ - node distance={20mm}, - thick, - main/.style = {draw, circle} - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [above right of=1] {$x_2$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - \node[main] (5) [above right of=4] {$x_5$}; - \node[main] (6) [below right of=4] {$x_6$}; - \node[main] (7) [below right of=5] {$x_7$}; - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (2) -- (5); - \draw[-] (2) -- (4); - \draw[-] (3) -- (6); - \draw[-] (3) -- (4); - \draw[-] (4) -- (5); - \draw[-] (5) -- (7); - \draw[-] (6) -- (7); - \end{tikzpicture} - \end{center} - \vfill - \pagebreak - - - During his stay in the city of K\"onigsberg, - then the capital of Prussia, Euler came up with - and solved the following problem: \\ - - Can one design a walk - that crosses each of the seven bridges in K\"onigsberg once and only once? - A map of K\"onigsberg in Euler's time is provided below. \\ - - \begin{center} - \includegraphics[width=3.5in]{bridges.png} \\ - \end{center} - \medskip - - \problem{} - Draw a graph with the vertices corresponding to - the landmasses from the picture above - and with the edges corresponding to - the K\"onigsberg's seven bridges. - What are the degrees of each of the graph's vertices? - \vfill - \pagebreak - - \problem{} - Is there an Eulerian path in this map of K\"onigsberg? Why or why not? - \vfill - - - \problem{} - Find a Eulerian path in the following graph. - - \begin{center} - \begin{tikzpicture} [scale = .8] - \tikzset{EdgeStyle/.append style = {-}} - \SetGraphUnit{3} - \Vertex{A} - \SOWE(A){B} - \SOEA(A){C} - \SO(A){D} - \Edge(A)(B) - \Edge(A)(C) - \Edge(A)(D) - \Edge(B)(D) - \Edge(C)(D) - \tikzset{EdgeStyle/.append style = {bend right = 70}} - \Edge(B)(C) - \Edge(C)(A) - \end{tikzpicture} - \end{center} - \vfill - - \problem{} - Does the above graph contain a Eulerian cycle? - Why or why not? - \vfill - \pagebreak - - - - - - - \problem{A Traveling Salesman} - A salesman with the home office in Albuquerque has to fly to Boston, Chicago, and Denver, visiting each city once, and then to come back to the home office. The order in which he visits the cities does not matter. The airfare prices, shown on the graph below, do not depend on the direction of the travel. Find the cheapest route. - - \newcommand{\test}{ - \begin{center} - \begin{normalsize} - \begin{tikzpicture} - \tikzset{EdgeStyle/.append style = {-}} - \SetGraphUnit{3} - \Vertex{A} - \SOWE(A){B} - \SOEA(A){C} - \SO(A){D} - \Edge(A)(B) - \Edge(A)(C) - \Edge(A)(D) - \Edge(B)(D) - \Edge(C)(D) - \tikzset{EdgeStyle/.append style = {bend right = 70}} - \Edge(B)(C) - \coordinate [label=left:{\$1400}] (ab) at (-1.8,-1.75); - \coordinate [label=right:{\$1000}] (ac) at (1.8,-1.75); - \coordinate [label=right:{\$400}] (ad) at (-.1,-1.75); - \coordinate [label=below:{\$800}] (bc) at (0,-4.8); - \coordinate [label=below:{\$1200}] (bd) at (-1.5,-3); - \coordinate [label=below:{\$900}] (cd) at (1.5,-3); - \end{tikzpicture} - \end{normalsize} - \end{center} - } - \test{} - - \vfill - Here's an extra copy of the graph. - - \test{} - - \vfill - \pagebreak - - \problem{} - On a test every student solved exactly 2 problems, and every problem was solved by exactly 2 students. - - \problempart{} - Show that the number of students in the class and the number of problems on the test are the same. - \vfill - - \problempart{} - The teacher wants to make every student present one problem they solved at the board. Show that it is possible to choose the problem each student presents so that every problem on the test gets presented exactly once. - \vfill - - - \vfill - \pagebreak - - - \section{Traversing Graphs} - - As you can imagine, it would be good to have computers help us with problems involving graphs. However, computers can't simply \textit{look} at a graph and provide a solution. If we want a computer's help, we must break our problems down into a series of steps. \\ - - \medskip - - First, let's look at ways to \textit{traverse} a graph. Say we're given a single node\footnotemark, and can only ``see'' the edges directly connected to it. We want to explore the whole graph. How can we do so? - \footnotetext{In graph theory, the terms ``node'' and ``vertex'' are equivalent.} - - - \begin{center} - \begin{tikzpicture}[ - node distance={20mm}, - thick, - main/.style = {draw, circle}, - scale = 0.4 - ] - - \node[main] (1) {$x_1$}; - \node (2) [below left of=1] {$?$}; - \node (3) [below right of=1] {$?$}; - \node (4) [above right of=3] {$?$}; - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (1) -- (4); - \end{tikzpicture} - \end{center} - - One way to go about this is an algorithm called \textit{breadth--first search.} Starting from our first node, we'll explore the nodes directly connected to it, then the nodes connected to \textit{those}, one at a time, and so on. \\ - First, we explore $x_2, x_3, x_4$, and find that they have a few edges too: - - - \begin{center} - \begin{tikzpicture}[ - node distance={20mm}, - thick, - main/.style = {draw, circle}, - scale = 0.4 - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [below left of=1] {$x_2$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - - \node (5) [below right of=2] {$?$}; - \node (7) [below right of=4] {$?$}; - - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (1) -- (4); - \draw[-] (3) -- (4); - - \draw[-] (2) -- (5); - \draw[-] (3) -- (5); - \draw[-] (4) -- (7); - - \end{tikzpicture} - \end{center} - - Then we explore $x_5$ and $x_6$: - - \begin{center} - \begin{tikzpicture}[ - node distance={20mm}, - thick, - main/.style = {draw, circle}, - scale = 0.4 - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [below left of=1] {$x_2$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - - \node[main] (5) [below right of=2] {$x_5$}; - \node (7) [below right of=3] {$?$}; - \node[main] (6) [below right of=4] {$x_6$}; - - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (1) -- (4); - \draw[-] (3) -- (4); - \draw[-] (2) -- (5); - \draw[-] (3) -- (5); - \draw[-] (4) -- (6); - - \draw[-] (5) -- (7); - \draw[-] (6) -- (7); - \end{tikzpicture} - \end{center} - - And finally, we explore $x_7$, and we're done. - \begin{center} - \begin{tikzpicture}[ - node distance={20mm}, - thick, - main/.style = {draw, circle}, - scale = 0.4 - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [below left of=1] {$x_2$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - - \node[main] (5) [below right of=2] {$x_5$}; - \node[main] (7) [below right of=3] {$x_7$}; - \node[main] (6) [below right of=4] {$x_6$}; - - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (1) -- (4); - \draw[-] (3) -- (4); - \draw[-] (2) -- (5); - \draw[-] (3) -- (5); - \draw[-] (4) -- (6); - - \draw[-] (5) -- (7); - \draw[-] (6) -- (7); - \end{tikzpicture} - \end{center} - - \vfill - \pagebreak - - While running a breadth-first search, we can arrange our nodes in ``layers.'' The first layer consists of our starting node, the second, of nodes directly connected to it, and so on. \\ - For example, we get the following if we do this with the graph above: - - \medskip - - \hfill - \begin{minipage}{.2\textwidth} - \begin{enumerate} - \item[Layer 1:] $x_1$ - \item[Layer 2:] $x_2, x_3, x_4$ - \item[Layer 3:] $x_5, x_6$ - \item[Layer 4:] $x_7$ - \end{enumerate} - \end{minipage}% - \hfill - \begin{minipage}{.4\textwidth} - \begin{center} - \begin{tikzpicture}[ - node distance={15mm}, - thick, - main/.style = {draw, circle}, - scale = 0.4 - ] - - \node[main] (1) {$x_1$}; - \node[main] (3) [below of=1] {$x_3$}; - \node[main] (2) [left of=3] {$x_2$}; - \node[main] (4) [right of=3] {$x_4$}; - - \node[main] (5) [below of=2] {$x_5$}; - \node[main] (6) [below of=4] {$x_6$}; - - \node (7_aux) [below of=3] {}; - \node[main] (7) [below of=7_aux] {$x_7$}; - - - \draw[-] (1) -- (2); - \draw[-] (1) -- (3); - \draw[-] (1) -- (4); - \draw[-] (3) -- (4); - \draw[-] (2) -- (5); - \draw[-] (3) -- (5); - \draw[-] (4) -- (6); - - \draw[-] (5) -- (7); - \draw[-] (6) -- (7); - \end{tikzpicture} - \end{center} - \end{minipage} - \hfill - - We'll call this resulting graph a \textit{bfs graph\footnotemark} of G. - \footnotetext{That is, a \textbf{b}readth-\textbf{f}irst \textbf{s}earch graph} - - \problem{} - Starting from $x_1$, draw the bfs graph of the following: - - \begin{center} - \begin{tikzpicture}[ - node distance={20mm}, - thick, - main/.style = {draw, circle}, - scale = 0.4 - ] - - \node[main] (1) {$x_1$}; - \node[main] (3) [below right of=1] {$x_3$}; - \node[main] (4) [above right of=3] {$x_4$}; - \node[main] (6) [below right of=4] {$x_6$}; - \node[main] (5) [above right of=6] {$x_5$}; - \node[main] (2) [below left of=1] {$x_2$}; - - - \draw[-] (1) -- (4); - \draw[-] (1) to [out=45,in=135,looseness=0.5] (5); - \draw[-] (4) -- (5); - \draw[-] (4) -- (6); - \draw[-] (4) -- (3); - \draw[-] (3) -- (2); - \draw[-] (3) -- (6); - \end{tikzpicture} - \end{center} - - \vfill - \pagebreak - - \definition{} - We say a graph is \textit{bipartite} if it can be split into two groups so that - no two nodes in the same group are connected. For example, the following graph is bipartite, since we can create two groups ($\{x_1, x_2, x_3\}$ and $\{x_4, x_5\}$) in which no nodes are connected. - - \begin{center} - \begin{tikzpicture}[ - node distance={15mm}, - thick, - main/.style = {draw, circle}, - scale = 0.4 - ] - - \node[main] (1) {$x_1$}; - \node[main] (2) [below of=1] {$x_2$}; - \node[main] (3) [below of=2] {$x_3$}; - - \node (middle_aux) [right of=1] {}; - - \node[main] (4) [below right of=middle_aux] {$x_4$}; - \node[main] (5) [below of=4] {$x_5$}; - - - \draw[-] (1) -- (4); - \draw[-] (2) -- (5); - \draw[-] (1) -- (5); - \draw[-] (3) -- (4); - \end{tikzpicture} - \end{center} - - - \problem{} - Which of the following graphs are bipartite? - - \begin{center} - \includegraphics[width=\textwidth]{graphs.png} \\ - \end{center} - - \vfill - \pagebreak - - \problem{} - Show that you only need two colors to color the nodes of a bipartite graph so that no two nodes of the same color are connected. - - \vfill - - \problem{} - Given a large graph, how can you check if it is bipartite? \\ - - \vfill - \vfill - \pagebreak \end{document} \ No newline at end of file diff --git a/Intermediate/An Introduction to Graph Theory/parts/0 intro.tex b/Intermediate/An Introduction to Graph Theory/parts/0 intro.tex new file mode 100644 index 0000000..f1f3a88 --- /dev/null +++ b/Intermediate/An Introduction to Graph Theory/parts/0 intro.tex @@ -0,0 +1,127 @@ +\section{Graphs} + +\definition{} +A \textit{set} is an unordered collection of objects. \par +This means that the sets $\{1, 2, 3\}$ and $\{3, 2, 1\}$ are identical. + + +\definition{} +A \textit{graph} $G = (N, E)$ consists of two sets: a set of \textit{vertices} $V$, and a set of \textit{edges} $E$. \par +Verticies are simply named \say{points,} and edges are connections between pairs of vertices. \par +In the graph below, $V = \{a, b, c, d\}$ and $E = \{~ (a,b),~ (a,c),~ (a,d),~ (c,d) ~\}$. + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (a) at (0, 0) {$a$}; + \node[main] (b) at (0, -1) {$b$}; + \node[main] (c) at (2, -1) {$c$}; + \node[main] (d) at (4, 0) {$d$}; + \end{scope} + + \draw[-] + (a) edge (b) + (a) edge (c) + (a) edge (d) + (c) edge (d) + ; +\end{tikzpicture} +\end{center} + +Vertices are also sometimes called \textit{nodes}. You'll see both terms in this handout. \par + + + +\problem{} +Draw the graph defined by the following vertex and edge sets: \par +$V = \{A,B,C,D,E\}$ \par +$E = \{~ (A,B),~ (A,C),~ (A,D),~ (A,E),~ (B,C),~ (C,D),~ (D,E) ~\}$\par + +\vfill + + +We can use graphs to solve many different kinds of problems. \par +Most situations that involve some kind of \say{relation} between elements can be represented by a graph. + +\pagebreak + + +Graphs are fully defined by their vertices and edges. The exact position of each vertex and edge doesn't matter---only which nodes are connected to each other. The same graph can be drawn in many different ways. + + +\problem{} +Show that the graphs below are equivalent by comparing the sets of their vertices and edges. + +\begin{center} +\adjustbox{valign=c}{ +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (a) at (0, 0) {$a$}; + \node[main] (b) at (2, 0) {$b$}; + \node[main] (c) at (2, -2) {$c$}; + \node[main] (d) at (0, -2) {$d$}; + \end{scope} + + \draw[-] + (a) edge (b) + (b) edge (c) + (c) edge (d) + (d) edge (a) + (a) edge (c) + (b) edge (d) + ; +\end{tikzpicture} +} +\hspace{20mm} +\adjustbox{valign=c}{ +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (a) at (0, 0) {$a$}; + \node[main] (b) at (-2, -2) {$b$}; + \node[main] (c) at (0, -2) {$c$}; + \node[main] (d) at (2, -2) {$d$}; + \end{scope} + + \draw[-] + (a) edge (b) + (b) edge (c) + (c) edge (d) + (d) edge (a) + (a) edge (c) + (b) edge[out=270, in=270, looseness=1] (d) + ; + \end{tikzpicture} +} +\end{center} +\vfill +\pagebreak + + +\definition{} +The degree $D(v)$ of a vertex $v$ of a graph +is the number of the edges of the graph +connected to that vertex. + + +\theorem{Handshake Lemma} +In any graph, the sum of the degrees of its vertices equals twice the number of the edges. + + +\problem{} +Prove \ref{handshake}. +\vfill + + +\problem{} +Show that all graphs have an even number number of vertices with odd degree. +\vfill + + +\problem{} +One girl tells another, \say{There are 25 kids +in my class. Isn't it funny that each of them +has 5 friends in the class?} \say{This cannot be true,} immediately replies the other girl. +How did she know? + +\vfill +\pagebreak \ No newline at end of file diff --git a/Intermediate/An Introduction to Graph Theory/parts/1 paths.tex b/Intermediate/An Introduction to Graph Theory/parts/1 paths.tex new file mode 100644 index 0000000..092bc6f --- /dev/null +++ b/Intermediate/An Introduction to Graph Theory/parts/1 paths.tex @@ -0,0 +1,237 @@ +\section{Paths and cycles} + +A \textit{path} in a graph is, intuitively, a sequence of edges: $(x_1, x_2, x_4, ... )$. \par +I've highlighted one possible path in the graph below. + +\begin{center} +\begin{tikzpicture}[ + node distance={15mm}, + thick, + main/.style = {draw, circle} +] + + \node[main] (1) {$x_1$}; + \node[main] (2) [above right of=1] {$x_2$}; + \node[main] (3) [below right of=1] {$x_3$}; + \node[main] (4) [above right of=3] {$x_4$}; + \node[main] (5) [above right of=4] {$x_5$}; + \node[main] (6) [below right of=4] {$x_6$}; + \node[main] (7) [below right of=5] {$x_7$}; + + \draw[-] (1) -- (2); + \draw[-] (1) -- (3); + \draw[-] (2) -- (5); + \draw[-] (2) -- (4); + \draw[-] (3) -- (6); + \draw[-] (3) -- (4); + \draw[-] (4) -- (5); + \draw[-] (5) -- (7); + \draw[-] (6) -- (7); + + \draw [ + line width=2mm, + draw=black, + opacity=0.4 + ] (1) -- (2) -- (4) -- (3) -- (6); +\end{tikzpicture} +\end{center} + +A \textit{cycle} is a path that starts and ends on the same vertex: + +\begin{center} + \begin{tikzpicture}[ + node distance={15mm}, + thick, + main/.style = {draw, circle} + ] + + \node[main] (1) {$x_1$}; + \node[main] (2) [above right of=1] {$x_2$}; + \node[main] (3) [below right of=1] {$x_3$}; + \node[main] (4) [above right of=3] {$x_4$}; + \node[main] (5) [above right of=4] {$x_5$}; + \node[main] (6) [below right of=4] {$x_6$}; + \node[main] (7) [below right of=5] {$x_7$}; + + \draw[-] (1) -- (2); + \draw[-] (1) -- (3); + \draw[-] (2) -- (5); + \draw[-] (2) -- (4); + \draw[-] (3) -- (6); + \draw[-] (3) -- (4); + \draw[-] (4) -- (5); + \draw[-] (5) -- (7); + \draw[-] (6) -- (7); + + \draw[ + line width=2mm, + draw=black, + opacity=0.4 + ] (2) -- (4) -- (3) -- (6) -- (7) -- (5) -- (2); +\end{tikzpicture} +\end{center} + + +A \textit{Eulerian\footnotemark} path is a path that traverses each edge exactly once. \par +A Eulerian cycle is a cycle that does the same. + +\footnotetext{Pronounced ``oiler-ian''. These terms are named after a Swiss mathematician, Leonhard Euler (1707-1783), who is usually considered the founder of graph theory.} + +\vspace{2mm} + +Similarly, a {\it Hamiltonian} path is a path in a graph that visits each vertex exactly once, \par +and a Hamiltonian cycle is a closed Hamiltonian path. + +\medskip + +An example of a Hamiltonian path is below. + +\begin{center} + \begin{tikzpicture}[ + node distance={15mm}, + thick, + main/.style = {draw, circle} + ] + + \node[main] (1) {$x_1$}; + \node[main] (2) [above right of=1] {$x_2$}; + \node[main] (3) [below right of=1] {$x_3$}; + \node[main] (4) [above right of=3] {$x_4$}; + \node[main] (5) [above right of=4] {$x_5$}; + \node[main] (6) [below right of=4] {$x_6$}; + \node[main] (7) [below right of=5] {$x_7$}; + + \draw[-] (1) -- (2); + \draw[-] (1) -- (3); + \draw[-] (2) -- (5); + \draw[-] (2) -- (4); + \draw[-] (3) -- (6); + \draw[-] (3) -- (4); + \draw[-] (4) -- (5); + \draw[-] (5) -- (7); + \draw[-] (6) -- (7); + + \draw [ + line width=2mm, + draw=black, + opacity=0.4 + ] (1) -- (2) -- (4) -- (3) -- (6) -- (7) -- (5); +\end{tikzpicture} +\end{center} + +\vfill +\pagebreak + + +\definition{} +We say a graph is \textit{connected} if there is a path between every pair of vertices. A graph is called \textit{disconnected} otherwise. + +\problem{} +Draw a disconnected graph with four vertices. \par +Then, draw a graph with four vertices, all of degree one. +\vfill + + +\problem{} +Find a Hamiltonian cycle in the following graph. + +\begin{center} + \begin{tikzpicture}[ + node distance={20mm}, + thick, + main/.style = {draw, circle} + ] + + \node[main] (1) {$x_1$}; + \node[main] (2) [above right of=1] {$x_2$}; + \node[main] (3) [below right of=1] {$x_3$}; + \node[main] (4) [above right of=3] {$x_4$}; + \node[main] (5) [above right of=4] {$x_5$}; + \node[main] (6) [below right of=4] {$x_6$}; + \node[main] (7) [below right of=5] {$x_7$}; + + \draw[-] (1) -- (2); + \draw[-] (1) -- (3); + \draw[-] (2) -- (5); + \draw[-] (2) -- (4); + \draw[-] (3) -- (6); + \draw[-] (3) -- (4); + \draw[-] (4) -- (5); + \draw[-] (5) -- (7); + \draw[-] (6) -- (7); +\end{tikzpicture} +\end{center} +\vfill +\pagebreak + + +\problem{} +Is there an Eulerian path in the following graph? \par + +\begin{center} + \begin{tikzpicture}[ + node distance={20mm}, + thick, + main/.style = {draw, circle} + ] + + \node[main] (1) {$x_1$}; + \node[main] (2) [above right of=1] {$x_2$}; + \node[main] (3) [below right of=1] {$x_3$}; + \node[main] (4) [above right of=3] {$x_4$}; + \node[main] (5) [above right of=4] {$x_5$}; + \node[main] (6) [below right of=4] {$x_6$}; + \node[main] (7) [below right of=5] {$x_7$}; + + \draw[-] (1) -- (2); + \draw[-] (1) -- (3); + \draw[-] (2) -- (5); + \draw[-] (2) -- (4); + \draw[-] (3) -- (6); + \draw[-] (3) -- (4); + \draw[-] (4) -- (5); + \draw[-] (5) -- (7); + \draw[-] (6) -- (7); +\end{tikzpicture} +\end{center} + +\vfill + +\problem{} +Is there an Eulerian path in the following graph? \par + +\begin{center} + \begin{tikzpicture}[ + node distance={20mm}, + thick, + main/.style = {draw, circle} + ] + + \node[main] (1) {$x_1$}; + \node[main] (2) [above right of=1] {$x_2$}; + \node[main] (3) [below right of=1] {$x_3$}; + \node[main] (4) [above right of=3] {$x_4$}; + \node[main] (5) [above right of=4] {$x_5$}; + \node[main] (6) [below right of=4] {$x_6$}; + \node[main] (7) [below right of=5] {$x_7$}; + + \draw[-] (1) -- (2); + \draw[-] (1) -- (3); + \draw[-] (2) -- (4); + \draw[-] (3) -- (6); + \draw[-] (3) -- (4); + \draw[-] (4) -- (5); + \draw[-] (5) -- (7); + \draw[-] (6) -- (7); +\end{tikzpicture} +\end{center} + + +\vfill + +\problem{} +When does an Eulerian path exist? \par +\hint{Look at the degree of each node.} + +\vfill +\pagebreak \ No newline at end of file diff --git a/Intermediate/An Introduction to Graph Theory/tikxset.tex b/Intermediate/An Introduction to Graph Theory/tikxset.tex new file mode 100644 index 0000000..384dcfa --- /dev/null +++ b/Intermediate/An Introduction to Graph Theory/tikxset.tex @@ -0,0 +1,42 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{patterns} + +% We put nodes in a separate layer, so we can +% slightly overlap with paths for a perfect fit +\pgfdeclarelayer{nodes} +\pgfdeclarelayer{path} +\pgfsetlayers{main,nodes} + +% Layer settings +\tikzset{ + % Layer hack, lets us write + % later = * in scopes. + layer/.style = { + execute at begin scope={\pgfonlayer{#1}}, + execute at end scope={\endpgfonlayer} + }, + % + % Arrowhead tweak + >={Latex[ width=2mm, length=2mm ]}, + % + % Labels inside edges + label/.style = { + rectangle, + % For automatic red background in solutions + fill = \ORMCbgcolor, + draw = none, + rounded corners = 0mm + }, + % + % Nodes + main/.style = { + draw, + circle, + fill = white, + line width = 0.4mm + }, + every path/.style = { + line width = 0.3mm + } +} \ No newline at end of file