diff --git a/README.md b/README.md index 48e9c22..2fd3b0e 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,20 @@ Using styling files from [oysteikt/texmf](https://gitlab.stud.idi.ntnu.no/oysteikt/texmf) -| Num | Exercise PDF | My Solution PDF | Answer Sheet PDF | -| --- | ------------------------ | --------------- | ---------------- | -| 1 | [wiki.math.ntnu.no][ex1] | [ex1.pdf][so1] | [wiki.math.ntnu.no][as1] | -| 2 | [wiki.math.ntnu.no][ex2] | [ex2.pdf][so2] | [wiki.math.ntnu.no][as2] | -| 3 | [wiki.math.ntnu.no][ex3] | [ex3.pdf][so3] | [wiki.math.ntnu.no][as3] | -| 4 | [wiki.math.ntnu.no][ex4] | [ex4.pdf][so4] | [wiki.math.ntnu.no][as4] | -| 5 | [wiki.math.ntnu.no][ex5] | [ex5.pdf][so5] | | -| 6 | [wiki.math.ntnu.no][ex6] | [ex6.pdf][so6] | | -| 7 | [wiki.math.ntnu.no][ex7] | [ex7.pdf][so7] | | -| 8 | [wiki.math.ntnu.no][ex8] | [ex8.pdf][so8] | | +| Num | Exercise PDF | Answer PDF | Solutions PDF | +| --- | ------------------------- | ---------------- | ------------------------- | +| 1 | [wiki.math.ntnu.no][ex1] | [ex1.pdf][as1] | [wiki.math.ntnu.no][so1] | +| 2 | [wiki.math.ntnu.no][ex2] | [ex2.pdf][as2] | [wiki.math.ntnu.no][so2] | +| 3 | [wiki.math.ntnu.no][ex3] | [ex3.pdf][as3] | [wiki.math.ntnu.no][so3] | +| 4 | [wiki.math.ntnu.no][ex4] | [ex4.pdf][as4] | [wiki.math.ntnu.no][so4] | +| 5 | [wiki.math.ntnu.no][ex5] | [ex5.pdf][as5] | [wiki.math.ntnu.no][as5] | +| 6 | [wiki.math.ntnu.no][ex6] | [ex6.pdf][as6] | [wiki.math.ntnu.no][as6] | +| 7 | [wiki.math.ntnu.no][ex7] | [ex7.pdf][as7] | [wiki.math.ntnu.no][as7] | +| 8 | [wiki.math.ntnu.no][ex8] | [ex8.pdf][as8] | [wiki.math.ntnu.no][as8] | +| 9 | [wiki.math.ntnu.no][ex9] | [ex9.pdf][as9] | [wiki.math.ntnu.no][as9] | +| 10 | [wiki.math.ntnu.no][ex10] | [ex10.pdf][as10] | [wiki.math.ntnu.no][as10] | +| 11 | [wiki.math.ntnu.no][ex11] | [ex11.pdf][as11] | N/A | +| 12 | [wiki.math.ntnu.no][ex12] | [ex12.pdf][as12] | N/A | [ex1]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-1-2021-new.pdf "Exercise 1 Questions" [ex2]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-2-2021-new.pdf "Exercise 2 Questions" @@ -23,17 +27,31 @@ Using styling files from [oysteikt/texmf](https://gitlab.stud.idi.ntnu.no/oystei [ex6]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-6-2021.pdf "Exercise 6 Questions" [ex7]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-7-2021.pdf "Exercise 7 Questions" [ex8]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-8-2021.pdf "Exercise 8 Questions" +[ex9]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-9-2021.pdf "Exercise 9 Questions" +[ex10]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-10-2021.pdf "Exercise 10 Questions" +[ex11]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-11-2021.pdf "Exercise 11 Questions" +[ex12]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-12-2021.pdf "Exercise 12 Questions" -[so1]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise1.pdf "Exercise 1 Solutions" -[so2]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise2.pdf "Exercise 2 Solutions" -[so3]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise3.pdf "Exercise 3 Solutions" -[so4]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise4.pdf "Exercise 4 Solutions" -[so5]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise5.pdf "Exercise 5 Solutions" -[so6]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise6.pdf "Exercise 6 Solutions" -[so7]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise7.pdf "Exercise 7 Solutions" -[so8]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise8.pdf "Exercise 8 Solutions" +[as1]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise1.pdf "Exercise 1 Answers" +[as2]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise2.pdf "Exercise 2 Answers" +[as3]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise3.pdf "Exercise 3 Answers" +[as4]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise4.pdf "Exercise 4 Answers" +[as5]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise5.pdf "Exercise 5 Answers" +[as6]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise6.pdf "Exercise 6 Answers" +[as7]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise7.pdf "Exercise 7 Answers" +[as8]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise8.pdf "Exercise 8 Answers" +[as9]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise9.pdf "Exercise 9 Answers" +[as10]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise10.pdf "Exercise 10 Answers" +[as11]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise11.pdf "Exercise 11 Answers" +[as12]: http://oysteikt.pages.stud.idi.ntnu.no/v21-ma0301/exercise12.pdf "Exercise 12 Answers" -[as1]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-1-2021-solutions.pdf "Exercise 1 Answer sheet" -[as2]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-2-2021-solutions.pdf "Exercise 2 Answer sheet" -[as3]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-3-2021-solutions.pdf "Exercise 3 Answer sheet" -[as4]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-4-2021-solutions.pdf "Exercise 4 Answer sheet" \ No newline at end of file +[so1]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-1-2021-solutions.pdf "Exercise 1 Solutions" +[so2]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-2-2021-solutions.pdf "Exercise 2 Solutions" +[so3]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-3-2021-solutions.pdf "Exercise 3 Solutions" +[so4]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-4-2021-solutions.pdf "Exercise 4 Solutions" +[so5]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-5-2021-solutions.pdf "Exercise 5 Solutions" +[so6]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-6-2021-solutions.pdf "Exercise 6 Solutions" +[so7]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-7-2021-solutions.pdf "Exercise 7 Solutions" +[so8]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-8-2021-solutions.pdf "Exercise 8 Solutions" +[so9]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-9-2021-solutions.pdf "Exercise 9 Solutions" +[so10]: https://wiki.math.ntnu.no/_media/ma0301/2021v/set-10-2021-solutions.pdf "Exercise 10 Solutions" \ No newline at end of file diff --git a/exercise10/diagrams/ex2.tex b/exercise10/diagrams/ex2.tex new file mode 100644 index 0000000..8d06b41 --- /dev/null +++ b/exercise10/diagrams/ex2.tex @@ -0,0 +1,14 @@ +\newcommand{\point}[2]{ + \node [label=above:$#1$] (#1) at #2 {}; +} + +\begin{tikzpicture}[] + \begin{scope}[every node/.style={fill=black, shape=circle, inner sep=1pt}] + \point{a}{(0,0)} + \point{b}{(1,0)} + \point{c}{(2,0)} + \end{scope} + + \draw (a) -- (b) -- (c); + +\end{tikzpicture} \ No newline at end of file diff --git a/exercise10/diagrams/ex3.tex b/exercise10/diagrams/ex3.tex new file mode 100644 index 0000000..fef3e0a --- /dev/null +++ b/exercise10/diagrams/ex3.tex @@ -0,0 +1,36 @@ +\newcommand{\point}[3]{ + \node [label=#3:$#1$] (#1) at #2 {}; +} + +\begin{tikzpicture}[] + \begin{scope}[every node/.style={fill=black, shape=circle, inner sep=1pt}] + % a + \point{d}{(0,1)}{left} + \point{h}{(0,0)}{below} + \point{e}{(1,1)}{right} + % i + \point{b}{(3,2)}{above} + \point{f}{(3,1)}{left} + \point{j}{(3,0)}{below} + \point{c}{(4,2)}{above} + % g + \point{k}{(4,0)}{below} + \end{scope} + + \begin{scope}[every node/.style={fill=red, shape=circle, inner sep=2pt}] + \point{a}{(0,2)}{above} + \point{i}{(1,0)}{below} + \point{g}{(4,1)}{right} + \end{scope} + + \draw (a) -- (d) -- (h); + \draw (e) -- (i); + \draw (b) -- (f) -- (j); + \draw (c) -- (g) -- (k); + \draw (a) -- (b) -- (c); + \draw (a) -- (e); + \draw (d) -- (e); + \draw (f) -- (g); + \draw (h) -- (i) -- (j) -- (k); + +\end{tikzpicture} \ No newline at end of file diff --git a/exercise10/diagrams/ex5_a.tex b/exercise10/diagrams/ex5_a.tex new file mode 100644 index 0000000..72b4edc --- /dev/null +++ b/exercise10/diagrams/ex5_a.tex @@ -0,0 +1,43 @@ +\newcommand{\point}[3]{ + \node [label=#3:$#1$] (#1) at #2 {}; +} + +\newcommand{\arrow}[2]{\path [-{Latex[scale=1]}] (#1) edge (#2);} + +\begin{tikzpicture} + + \begin{scope}[every node/.style={fill=black, shape=circle, inner sep=1pt}] + \point{a}{(0,2)}{above} + \point{d}{(0,1)}{left} + \point{h}{(0,0)}{below} + \point{b}{(2,2)}{above} + \point{e}{(1,1)}{above left} + \point{i}{(1,0)}{below} + \point{f}{(3,1)}{right} + \point{j}{(3,0)}{below} + \point{c}{(4,2)}{above} + \point{g}{(4,1)}{right} + \point{k}{(4,0)}{below} + \end{scope} + + \arrow{a}{d} + \arrow{d}{h} + \arrow{h}{i} + \arrow{i}{j} + \arrow{j}{k} + \arrow{k}{g} + \arrow{g}{c} + \arrow{c}{b} + \arrow{b}{g} + \arrow{g}{j} + \arrow{j}{f} + \arrow{f}{b} + \arrow{b}{e} + \arrow{e}{f} + \arrow{f}{i} + \arrow{i}{e} + \arrow{e}{d} + \arrow{d}{b} + \arrow{b}{a} + +\end{tikzpicture} diff --git a/exercise10/diagrams/ex5_b.tex b/exercise10/diagrams/ex5_b.tex new file mode 100644 index 0000000..7869125 --- /dev/null +++ b/exercise10/diagrams/ex5_b.tex @@ -0,0 +1,42 @@ +\newcommand{\point}[3]{ + \node [label=#3:$#1$] (#1) at #2 {}; +} + +\newcommand{\arrow}[2]{\path [-{Latex[scale=1]}] (#1) edge (#2);} + +\begin{tikzpicture} + + \begin{scope}[every node/.style={fill=black, shape=circle, inner sep=1pt}] + \point{a}{(0,2)}{above} + \point{d}{(0,1)}{left} + \point{h}{(0,0)}{below} + \point{b}{(2,2)}{above} + \point{e}{(1,1)}{above left} + \point{i}{(1,0)}{below} + \point{f}{(3,1)}{right} + \point{j}{(3,0)}{below} + \point{c}{(4,2)}{above} + \point{g}{(4,1)}{right} + \point{k}{(4,0)}{below} + \end{scope} + + \arrow{d}{a} + \arrow{a}{b} + \arrow{b}{d} + \arrow{d}{h} + \arrow{h}{i} + \arrow{i}{j} + \arrow{j}{k} + \arrow{k}{g} + \arrow{g}{c} + \arrow{c}{b} + \arrow{b}{g} + \arrow{g}{j} + \arrow{j}{f} + \arrow{f}{b} + \arrow{b}{e} + \arrow{e}{f} + \arrow{f}{i} + \arrow{i}{e} + +\end{tikzpicture} diff --git a/exercise10/diagrams/ex6_b.svg b/exercise10/diagrams/ex6_b.svg new file mode 100644 index 0000000..c988222 --- /dev/null +++ b/exercise10/diagrams/ex6_b.svg @@ -0,0 +1,618 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + a + d + c + + diff --git a/exercise10/main.tex b/exercise10/main.tex new file mode 100644 index 0000000..38fdb27 --- /dev/null +++ b/exercise10/main.tex @@ -0,0 +1,116 @@ +\documentclass[12pt]{article} +\usepackage{ntnu} +\usepackage{ntnu-math} + +\author{Øystein Tveit} +\title{MA0301 Exercise 10} + +\usepackage{amsthm} +\usepackage{mathabx} + +\usetikzlibrary{arrows.meta} + +\begin{document} + \ntnuTitle{} + \break{} + + Because there are no exercise where there are multiple edges between two vertices, I will use strings of vertex names to represent a walk. + + \begin{excs} + + \exc{} + \begin{subexcs} + + \subexc{} + \[ bcbcd \] + + \subexc{} + \[ bacbed \] + + \subexc{} + \[ bcd \] + + \subexc{} + \[ bcb \] + + \subexc{} + \[ befgedcb \] + + \subexc{} + \[ bacb \] + + \end{subexcs} + + \exc{} + + \begin{figure}[H] + \center + \scalebox{2}{ + \input{diagrams/ex2.tex} + } + \end{figure} + + \exc{} + + By using trial and error, starting with the nodes that had a higher degree, I managed to bring it down to three nodes. + + \includeDiagram[scale=2, width=12cm]{diagrams/ex3.tex} + + The red vertices represent the guards + + \exc{} + \begin{subexcs} + \subexc{} + The graphs are not isomorphic because the shortest cycle between the vertices with a degree of 3 has a different length. + + \subexc{} + The graphs are isomorphic + + \end{subexcs} + + \exc{} + + \begin{subexcs} + \subexc{} + + \includeDiagram[scale=2, width=12cm]{diagrams/ex5_a.tex} + + \[ adhijkgcbgjfbefiedba \] + + \subexc{} + Because $deg(e) = deg(f) = 3$ is now odd, they have to be the starting vertex and ending vertex. + + \includeDiagram[scale=2, width=12cm]{diagrams/ex5_b.tex} + + \[ dabdhijkgcbgjfbefie \] + + \end{subexcs} + + \exc{} + + \begin{subexcs} + \subexc{} + $G_1$ is not an induced subgraph if it's missing an edge $e_1$ between $v_1, v_2 \in G_1$ where $e_1 \in G$ + + \subexc{} + \includeDiagram[scale=0.8, width=6cm, pdf=true]{diagrams/ex6_b.pdf} + + $G_1$ contains the vertices $c$ and $d$ while it is missing the edge $cd$ even though $cd$ was present in $G$. Therefore, it is not an induced subgraph + + \end{subexcs} + + \exc{} + + \begin{align*} + \sum_{deg(v) \in V} = 2 |E| \\ + 3|V| \leq 2 |E| \\ + |V| \leq \frac{2 |E|}{3} \\ + |V| \leq \frac{2 \cdot 17}{3} \\ + |V| \leq \frac{34}{3} \\ + |V| \leq 11.33 \\ + \end{align*} + + The max amount of vertices in $G$ has to be $11$ + + \end{excs} +\end{document} \ No newline at end of file diff --git a/exercise11/diagrams/ex2_1.tex b/exercise11/diagrams/ex2_1.tex new file mode 100644 index 0000000..d6030bc --- /dev/null +++ b/exercise11/diagrams/ex2_1.tex @@ -0,0 +1,24 @@ +\newcommand{\point}[3]{ + \node [label=#3:$#1$] (#1) at #2 {}; +} + +\begin{tikzpicture}[] + \begin{scope}[every node/.style={fill=black, shape=circle, inner sep=1pt}] + \point{a}{(0,1)}{left} + \point{b}{(1,2)}{above} + \point{c}{(2,1)}{above right} + \point{d}{(1,0)}{below} + + \point{e}{(4,1)}{above left} + \point{f}{(5,2)}{above} + \point{g}{(6,1)}{right} + \point{h}{(5,0)}{below} + \end{scope} + + \draw (a) -- (b) -- (c) -- (d) -- (a); + \draw (e) -- (f) -- (g) -- (h) -- (e); + \draw (b) -- (f); + \draw (c) -- (e); + \draw (d) -- (h); + +\end{tikzpicture} \ No newline at end of file diff --git a/exercise11/diagrams/ex2_2.tex b/exercise11/diagrams/ex2_2.tex new file mode 100644 index 0000000..3c00a3b --- /dev/null +++ b/exercise11/diagrams/ex2_2.tex @@ -0,0 +1,27 @@ +\newcommand{\point}[3]{ + \node [label=#3:$#1$] (#1) at #2 {}; +} + +\begin{tikzpicture}[] + \begin{scope}[every node/.style={fill=black, shape=circle, inner sep=1pt}] + \point{a}{(0,1)}{left} + \point{b}{(1,2)}{above} + \point{c}{(2,1)}{above right} + \point{d}{(1,0)}{below} + + \point{e}{(4,1)}{above left} + \point{f}{(5,2)}{above} + \point{g}{(6,1)}{right} + \point{h}{(5,0)}{below} + \end{scope} + + + \draw (a) -- (b); + \draw (e) -- (f); + \draw (c) -- (d); + \draw (h) -- (e); + \draw (b) -- (c); + \draw (f) -- (g); + \draw (c) -- (e); + +\end{tikzpicture} \ No newline at end of file diff --git a/exercise11/main.tex b/exercise11/main.tex new file mode 100644 index 0000000..a04b041 --- /dev/null +++ b/exercise11/main.tex @@ -0,0 +1,211 @@ +\documentclass[12pt]{article} +\usepackage{ntnu} +\usepackage{ntnu-math} +\usepackage{ntnu-code} + +\author{Øystein Tveit} +\title{MA0301 Exercise 11} + +\begin{document} + \ntnuTitle{} + \break{} + + \begin{excs} + + \exc{} + + \[n^{n-2} = 4^{4-2} = 4^{2} = 16\] + + \exc{} + + To solve this exercise, I chose to implement the algorithm in python + + In order to keep track of the nodes, I have given them the following labels + + \includeDiagram[width=13cm, scale=1.6]{diagrams/ex2_1.tex} + + \break + + \codeFile{scripts/Kruskal.py}{python} + + Output: + \begin{verbatim} +[('a', 'b'), ('e', 'f'), ('c', 'd'), ('h', 'e'), ('b', 'c'), ('f', 'g'), + ('c', 'e')] + \end{verbatim} + + When we connect the nodes, we get the minimal spanning tree: + + \includeDiagram[width=13cm, scale=1.6]{diagrams/ex2_2.tex} + + \exc{} + \begin{subexcs} + \subexc{} + By counting the vertices, edges and regions, we can see that + + \begin{align*} + |V| &= 17 \\ + |E| &= 34 \\ + |R| &= 19 + \end{align*} + + By applying Eulers theorem, we can confirm that this is a possible graph + + \begin{align*} + V + R - E &= 2 \\ + 17 + 19 - 34 &= 2 \\ + 36 - 34 &= 2 \\ + 2 &= 2 + \end{align*} + + \subexc{} + By counting the vertices, edges and regions, we can see that + + \begin{align*} + |V| &= 10 \\ + |E| &= 24 \\ + |R| &= 16 + \end{align*} + + By applying Eulers theorem, we can confirm that this is a possible graph + + \begin{align*} + V + R - E &= 2 \\ + 10 + 16 - 24 &= 2 \\ + 26 - 24 &= 2 \\ + 2 &= 2 + \end{align*} + + \end{subexcs} + + \exc{} + + Every edge touches 2 regions. And every is connected to at least 5 edges. Therefore the amount of edges will be + + \[ E \geq \frac{53 \cdot 5}{2} = 132.5 \] + + Since the amount of edges has to be an integer, we can round it up to $E \geq 133$ + + Now we can use Eulers theorem for planar graphs to determine the amount of vertices + + \begin{align*} + V + R - E &= 2 \\ + V &= 2 - R + E \\ + V &\geq 2 - 53 + 133 \\ + V &\geq 82 + \end{align*} + + Therefore $|V| \geq 82$ + + \exc{} + \begin{subexcs} + \subexc{} + + By flipping the matrix once vertically and once horizontally, the matrix will equal the other matrix. + + Because flipping a matrix is a bijective function, composing two of them will also make a bijective function. + + After checking that the last matrix is a valid undirected graph, it is safe to conclude that the graphs are isomorphic + + \[ + \begin{bmatrix} + 0 & 0 & 1 \\ + 0 & 0 & 1 \\ + 1 & 1 & 0 + \end{bmatrix} + \cong + \begin{bmatrix} + 1 & 0 & 0 \\ + 1 & 0 & 0 \\ + 0 & 1 & 1 + \end{bmatrix} + \cong + \begin{bmatrix} + 0 & 1 & 1 \\ + 1 & 0 & 0 \\ + 1 & 0 & 0 + \end{bmatrix} + \] + + \subexc{} + By the same reasoning as \textbf{a)}, we have the following + + \[ + \begin{bmatrix} + 0 & 1 & 0 & 1 \\ + 1 & 0 & 1 & 1 \\ + 0 & 1 & 0 & 1 \\ + 1 & 1 & 1 & 0 + \end{bmatrix} + \cong + \begin{bmatrix} + 1 & 0 & 1 & 0 \\ + 1 & 1 & 0 & 1 \\ + 1 & 0 & 1 & 0 \\ + 0 & 1 & 1 & 1 + \end{bmatrix} + \cong + \begin{bmatrix} + 0 & 1 & 1 & 1 \\ + 1 & 0 & 1 & 0 \\ + 1 & 1 & 0 & 1 \\ + 1 & 0 & 1 & 0 + \end{bmatrix} + \] + \end{subexcs} + + \exc{} + \begin{subexcs} + \subexc{} + \[ uv = ababbab \] + \[ |uv| = 7 \] + + \subexc{} + \[ vu = bababab \] + \[ |vu| = 7 \] + + \subexc{} + \[ v^2 = babbab \] + \[ |v^2| = 6 \] + \end{subexcs} + + \exc{} + \begin{subexcs} + \subexc{} + \[ KL = \{ ab^2, abb^2, a^2b^2, aaba, ababa, a^2aba \} \] + + \subexc{} + + \[ LL = \{ b^2b^2, b^2aba, abab^2, abaaba \} \] + + \end{subexcs} + + \exc{} + \begin{subexcs} + \subexc{} + \[ L^* = \{b^2\}^* \] + + \subexc{} + \[ L^* = \{a,b\}^* \] + + \subexc{} + \[ L^* = \{a,b,c^3\}^* \] + + \end{subexcs} + + \exc{} + \begin{subexcs} + \subexc{} + $w$ does not belong to $r$ because $w$ is does neither fit $a^*$ nor $(b \vee c)^*$ + + \subexc{} + $w$ does belong to $r$ because $w$ is exactly $(a \cdot 1) (b \vee c \cdot 2)$ + + \end{subexcs} + + + + + + \end{excs} +\end{document} \ No newline at end of file diff --git a/exercise11/scripts/Kruskal.py b/exercise11/scripts/Kruskal.py new file mode 100644 index 0000000..06fac34 --- /dev/null +++ b/exercise11/scripts/Kruskal.py @@ -0,0 +1,40 @@ +def kruskal(vs, es): + f = [] + sets = [set(v) for v in vs] + + find_set = lambda v: [x for x in sets if v in x][0] + + def merge_sets_that_contains(u, v): + setv = find_set(v) + newsets = [x for x in sets if v not in x] + newsets = [setv.union(x) if u in x else x for x in newsets] + return newsets + + sorted_es = [e for e,w in sorted(es, key=lambda e: e[1])] + + for (u, v) in sorted_es: + if find_set(u) != find_set(v): + f += [(u, v)] + sets = merge_sets_that_contains(u,v) + + return f + +if __name__ == '__main__': + vs = [chr(i) for i in range(ord('a'), ord('h') + 1)] + es = [ + (('a', 'b'), 1), + (('b', 'c'), 5), + (('c', 'd'), 3), + (('d', 'a'), 7), + + (('e', 'f'), 2), + (('f', 'g'), 6), + (('g', 'h'), 8), + (('h', 'e'), 4), + + (('b', 'f'), 10), + (('c', 'e'), 9), + (('d', 'h'), 11) + ] + + print(kruskal(vs,es)) diff --git a/exercise12/diagrams/ex3.tex b/exercise12/diagrams/ex3.tex new file mode 100644 index 0000000..cae17e7 --- /dev/null +++ b/exercise12/diagrams/ex3.tex @@ -0,0 +1,21 @@ +% https://www3.nd.edu/~kogge/courses/cse30151-fa17/Public/other/tikz_tutorial.pdf + +\begin{tikzpicture} + \tikzset{ + ->, % makes the edges directed + >=Stealth, % makes the arrow heads bold + node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary. + every state/.style={thick, fill=white}, % sets the properties for each ’state’ node + initial text=$ $, % sets the text that appears on the start arrow + } + + \node[state, initial] (s0) {$s_0$}; + \node[state, below of=s0] (s1) {$s_1$}; + \node[state, accepting, right of=s0] (s2) {$s_2$}; + + \draw (s0) edge[right] node{b} (s1) + (s0) edge[above] node{a} (s2) + (s1) edge[loop below] node{a, b} (s1) + (s2) edge[bend left, right] node{a} (s1) + (s2) edge[loop above] node{b} (s2); +\end{tikzpicture} \ No newline at end of file diff --git a/exercise12/diagrams/ex6_b.tex b/exercise12/diagrams/ex6_b.tex new file mode 100644 index 0000000..6f204cf --- /dev/null +++ b/exercise12/diagrams/ex6_b.tex @@ -0,0 +1,26 @@ + +\begin{tikzpicture} + \tikzset{ + ->, % makes the edges directed + >=Stealth, % makes the arrow heads bold + node distance=5cm, % specifies the minimum distance between two nodes. Change if necessary. + every state/.style={thick, fill=white}, % sets the properties for each ’state’ node + initial text=$ $, % sets the text that appears on the start arrow + } + + \node[state] (s0) {$s_0$}; + \node[state, right of=s0] (s2) {$s_2$}; + \node[state, below of=s0] (s3) {$s_3$}; + \node[state, right of=s3] (s1) {$s_1$}; + + \draw (s0) edge[loop above, above] node{a,0} (s0) + (s0) edge[right] node{b,1} (s3) + (s0) edge[above] node{c,1} (s2) + (s1) edge[below, loop below] node{(a,0), (b,0)} (s1) + (s1) edge[below] node{c,1} (s3) + (s2) edge[right] node{(a,1), (b,1)} (s1) + (s2) edge[below right, bend left] node{c,0} (s3) + (s3) edge[above left, bend left] node{a,1} (s2) + (s3) edge[below, loop below] node{b,0} (s3) + (s3) edge[left, bend left] node{c,1} (s0); +\end{tikzpicture} \ No newline at end of file diff --git a/exercise12/main.tex b/exercise12/main.tex new file mode 100644 index 0000000..187b2a1 --- /dev/null +++ b/exercise12/main.tex @@ -0,0 +1,110 @@ +\documentclass[12pt]{article} +\usepackage{ntnu} +\usepackage{ntnu-math} + +\author{Øystein Tveit} +\title{MA0301 Exercise 12} + +\usetikzlibrary{automata, positioning, arrows.meta} + +\begin{document} + \ntnuTitle{} + \break{} + + \begin{excs} + + \exc{} + + \[ r = \{a,b\}^* a \{a,b\}^* a \{a,b\}^* a \{a,b\}^* \] + + \exc{} + \begin{subexcs} + \subexc{} + \[ \{ab\} \{ab\}^* \] + + \subexc{} + \[ a (a | \lambda) b (b | \lambda)\] + + \end{subexcs} + + \exc{} + + \[ M = (Q, \Sigma, \delta, s, F) \] + + \begin{align*} + Q &= \{ s_0, s_1, s_2 \} \\ + \Sigma &= \{a, b\} \\ + \delta &= \begin{Bmatrix} + s_0 \xrightarrow{b} s_1, \\ + s_0 \xrightarrow{a} s_2, \\ + s_1 \xrightarrow{a,b} s_1, \\ + s_2 \xrightarrow{a} s_1, \\ + s_2 \xrightarrow{b} s_2 + \end{Bmatrix} \\ + s &= s_0 \\ + F &= \{ s_2 \} + \end{align*} + + \includeDiagram[scale=1.6, width=10cm]{diagrams/ex3.tex} + + \exc{} + + The words $L$ can be described by the regular expression $r$ where + + \[ r = a^* b b^* a \{a,b\}^* \] + + \exc{} + + The words in $L$ can be described by the regular expression $r$ where + + \[ r = (a^* b)^3 \{ (a^* b)^4 \} \] + + \exc{} + \begin{subexcs} + \subexc{} + \begin{align*} + s_0 &\xrightarrow{a, 0} s_0 \\ + s_0 &\xrightarrow{a, 0} s_0 \\ + s_0 &\xrightarrow{b, 1} s_3 \\ + s_3 &\xrightarrow{b, 0} s_3 \\ + s_3 &\xrightarrow{c, 1} s_0 \\ + s_0 &\xrightarrow{c, 1} s_2 + \end{align*} + + The output would be $001011$ + + \subexc{} + \includeDiagram[scale=1.2, width=13cm]{diagrams/ex6_b.tex} + + \end{subexcs} + + \exc{} + \begin{subexcs} + \subexc{} + Suppose we have $a \in A, b \in B$ + + \begin{align*} + AB^* &= \{a, ab, ab^2, ab^3, \ldots \} \\ + &= \{a\} \cup \{ab, ab^2, ab^3, \ldots \} \\ + &= A \cup \{ab, ab^2, ab^3, \ldots \} \\ + &\Rightarrow A \subseteq AB^* + \end{align*} + \qed + + \subexc{} + Since $A \subseteq B$, we can rewrite $B$ as $A \cup \overline{A}$ where $\overline{A} = \{b \mid b \in B, b \notin A \}$ + + \begin{align*} + B^* &= (A \cup \overline{A})^* \\ + &= A^* \cap \overline{A}^* \cap B_1, \qquad B_1 = \{(B^*\ a\ B^*\ a_1\ B^*) \vee (B^*\ a_1\ B^*\ a\ B^*) \mid a \in A, a_1 \in \overline{A}\} \\ + &\Rightarrow A^* \subseteq B^* + \end{align*} + \qed + + + \end{subexcs} + + + + \end{excs} +\end{document} \ No newline at end of file diff --git a/exercise9/diagrams/ex9_1.tex b/exercise9/diagrams/ex9_1.tex new file mode 100644 index 0000000..550859f --- /dev/null +++ b/exercise9/diagrams/ex9_1.tex @@ -0,0 +1,29 @@ + + \def\cone{(90:2cm) circle (2.5cm)} + \def\ctwo{(180:2cm) circle (2.5cm)} + \def\cthree{(270:2cm) circle (2.5cm)} + \def\cfour{(360:2cm) circle (2.5cm)} + \def\universe{(-5, -5) rectangle (5,5)} + \begin{tikzpicture}[scale=0.8] + + \fill[cyan] \universe; + \begin{scope} + \clip \ctwo; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cthree; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cfour; + \fill[white] \universe; + \end{scope} + + \draw \cone node[text=black,above] {$c_1$}; + \draw \ctwo node [text=black,left] {$c_2$}; + \draw \cthree node [text=black,below] {$c_3$}; + \draw \cfour node [text=black,right] {$c_4$}; + \draw \universe; + \draw (0, 5) node [text=black,above] {$N$}; + \end{tikzpicture} \ No newline at end of file diff --git a/exercise9/diagrams/ex9_2.tex b/exercise9/diagrams/ex9_2.tex new file mode 100644 index 0000000..f0b2768 --- /dev/null +++ b/exercise9/diagrams/ex9_2.tex @@ -0,0 +1,30 @@ + + \def\cone{(90:2cm) circle (2.5cm)} + \def\ctwo{(180:2cm) circle (2.5cm)} + \def\cthree{(270:2cm) circle (2.5cm)} + \def\cfour{(360:2cm) circle (2.5cm)} + \def\universe{(-5, -5) rectangle (5,5)} + \begin{tikzpicture}[scale=0.8] + + \fill[white] \universe; + \fill[red] \cone; + \begin{scope} + \clip \ctwo; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cthree; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cfour; + \fill[white] \universe; + \end{scope} + + \draw \cone node[text=black,above] {$c_1$}; + \draw \ctwo node [text=black,left] {$c_2$}; + \draw \cthree node [text=black,below] {$c_3$}; + \draw \cfour node [text=black,right] {$c_4$}; + \draw \universe; + \draw (0, 5) node [text=black,above] {$N$}; + \end{tikzpicture} \ No newline at end of file diff --git a/exercise9/diagrams/ex9_3.tex b/exercise9/diagrams/ex9_3.tex new file mode 100644 index 0000000..628f30f --- /dev/null +++ b/exercise9/diagrams/ex9_3.tex @@ -0,0 +1,33 @@ + + \def\cone{(90:2cm) circle (2.5cm)} + \def\ctwo{(180:2cm) circle (2.5cm)} + \def\cthree{(270:2cm) circle (2.5cm)} + \def\cfour{(360:2cm) circle (2.5cm)} + \def\universe{(-5, -5) rectangle (5,5)} + \begin{tikzpicture}[scale=0.8] + + \fill[ForestGreen] \universe; + \begin{scope} + \clip \cone; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \ctwo; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cthree; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cfour; + \fill[white] \universe; + \end{scope} + + \draw \cone node[text=black,above] {$c_1$}; + \draw \ctwo node [text=black,left] {$c_2$}; + \draw \cthree node [text=black,below] {$c_3$}; + \draw \cfour node [text=black,right] {$c_4$}; + \draw \universe; + \draw (0, 5) node [text=black,above] {$N(\overline{c}_1\overline{c}_2\overline{c}_3\overline{c}_4)$}; + \end{tikzpicture} \ No newline at end of file diff --git a/exercise9/diagrams/ex9_4.tex b/exercise9/diagrams/ex9_4.tex new file mode 100644 index 0000000..79fad85 --- /dev/null +++ b/exercise9/diagrams/ex9_4.tex @@ -0,0 +1,33 @@ + + \def\cone{(90:2cm) circle (2.5cm)} + \def\ctwo{(180:2cm) circle (2.5cm)} + \def\cthree{(270:2cm) circle (2.5cm)} + \def\cfour{(360:2cm) circle (2.5cm)} + \def\universe{(-5, -5) rectangle (5,5)} + \begin{tikzpicture}[scale=0.8] + + \fill[ForestGreen] \universe; + \begin{scope} + \clip \cone; + \fill[red] \universe; + \end{scope} + \begin{scope} + \clip \ctwo; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cthree; + \fill[white] \universe; + \end{scope} + \begin{scope} + \clip \cfour; + \fill[white] \universe; + \end{scope} + + \draw \cone node[text=black,above] {$c_1$}; + \draw \ctwo node [text=black,left] {$c_2$}; + \draw \cthree node [text=black,below] {$c_3$}; + \draw \cfour node [text=black,right] {$c_4$}; + \draw \universe; + \draw (0, 5) node [text=black,above] {$N$}; + \end{tikzpicture} \ No newline at end of file diff --git a/exercise9/main.tex b/exercise9/main.tex new file mode 100644 index 0000000..4655917 --- /dev/null +++ b/exercise9/main.tex @@ -0,0 +1,227 @@ +\documentclass[12pt]{article} +\usepackage{ntnu} +\usepackage{ntnu-math} + +\author{Øystein Tveit} +\title{MA0301 Exercise 9} + +\usepackage{amsthm} +\usepackage{mathabx} + +\begin{document} + \ntnuTitle{} + \break{} + + \begin{excs} + + \exc{} + \begin{align*} + p \rightarrow (q \vee r) &\equiv \neg p \vee (q \vee r) \\ + &\equiv \neg p \vee q \vee r \\ + &\equiv \neg (p \vee \neg q) \vee r \\ + &\equiv (p \vee \neg q) \rightarrow r \\ + \end{align*} + + \exc{} + + R does not define a partial orderering, because it is not transitive. + + $aRb$ and $bRc$, however $\neg aRc$ + + \exc{} + \begin{subexcs} + \subexc{} + \begin{gather*} + xyz + xy\overline{z}+\overline{x}y \\ + xy + \overline{x}y \\ + y + \end{gather*} + + \subexc{} + \begin{gather*} + y + \overline{x}z + x\overline{y} \\ + y + \overline{x}z + x \\ + y + z + x \\ + x + y + z + \end{gather*} + + \end{subexcs} + + \exc{} + + Step 1: + + \begin{align*} + \sum^1_{n=1}\frac{1}{(2n-1)(2n+1)} &= \frac{1}{2\cdot1 + 1} \\ + \frac{1}{(2\cdot1-1)(2\cdot1+1)} &= \frac{1}{3} \\ + \frac{1}{(1)(3)} &= \frac{1}{3} \\ + \frac{1}{3} &= \frac{1}{3} \\ + \end{align*} + + Step 2: + + Assume + + \[ \sum^k_{n=1} \frac{1}{(2n-1)(2n+1)} = \frac{k}{2k+1} \] + + then + + \begin{align*} + \sum^{k+1}_{n=1} \frac{1}{(2n-1)(2n+1)} &= \frac{k}{2k+1} \\[2ex] + &= \frac{1}{(2\cdot1 - 1)(2\cdot1+1)} + \frac{1}{(2\cdot2 - 1)(2\cdot2+1)} + \ldots \\[2ex] + &\qquad + \frac{1}{(2\cdot k - 1)(2\cdot k+1)} + \frac{1}{(2\cdot(k+1) - 1)(2\cdot(k+1)+1)} \\[2ex] + &= \frac{k}{2k+1} + \frac{1}{(2\cdot(k+1) - 1)(2\cdot(k+1)+1)} \\[2ex] + &= \frac{k}{2k+1} + \frac{1}{(2k+1)(2k+3)} \\[2ex] + &= \frac{k(2k1)(2k+3) + (2k+1)}{(2k+1)^2(2k+3)} \\[2ex] + &= \frac{k(2k+3) + 1}{(2k+1)(2k+3)} \\[2ex] + &= \frac{2k^2+3k + 1}{(2k+1)(2k+3)} \\[2ex] + &= \frac{(2k+1)(k+1)}{(2k+1)(2k+3)} \\[2ex] + &= \frac{(k+1)}{(2k+3)} \\[2ex] + &= \frac{k+1}{2(k+1)+1} + \end{align*} + + \exc{} + + \textbf{Injective:} + + Suppose $a,b \in \R$ + + \begin{align*} + f(a) &= f(b) \\ + 2a-3 &= 2b-3 \\ + 2a &= 2b \\ + a &= b \\ + \end{align*} + + thus + + \[ f(a) = f(b) \Leftrightarrow a = b \] + + which means that $f$ is injective \\ + + \textbf{Surjective:} + + Suppose $a \in \R$ + + \begin{align*} + a &= 2x-3 \\ + x &= \frac{a+3}{2} \\ + a &\in \R + \end{align*} + + therefore $f$ is surjective \\ + + \textbf{Inverse:} + + \begin{align*} + y &= 2x-3 \\[2ex] + x &= \frac{y+3}{2} \\[2ex] + f^{-1}(y) &= \frac{y+3}{2} + \end{align*} + + + \exc{} + + \begin{gather*} + (\overline{X \cap Y \cap Z}) \\ + \{ x \mid x \in \overline{X \cap Y \cap Z} \} \\ + \{ x \mid x \notin X \cap Y \cap Z \} \\ + \{ x \mid x \notin X \wedge x \notin Y \wedge x \notin Z \} \\ + \{ x \mid x \in \overline{X} \vee x \in \overline{Y} \vee x \in \overline{Z} \} \\ + \{ x \mid x \in \overline{X} \cup \overline{Y} \cup \overline{Z} \} \\ + \overline{X} \cup \overline{Y} \cup \overline{Z} + \end{gather*} + + \exc{} + + Assuming 'dozen' is to be interpreted as 12 + + \begin{subexcs} + \subexc{} + + \[ \nPr{31}{12} = 67\ 596\ 957\ 267\ 840\ 000 \] + + \subexc{} + + \[ 31^{12} = 787\ 662\ 783\ 788\ 549\ 761 \] + + \end{subexcs} + + \exc{} + \begin{subexcs} + \subexc{} + If we imagine a row of numbers going from 1 to 40, we can rephrase the question as how many ways we can split + the numbers into $5$ chunks. Imagine a chunk as inserting $4$ delimiters like this: + + \[ 1\ 2\ 3\ |\ 4\ 5\ 6\ 7\ |\ 8\ 9\ 10\ |\ 11\ \ldots\ 39\ |\ 40 \] + + In this case, we split the amount of numbers so that $x_1 = 3, x_2 = 4, x_3 = 3, x_4 = 29, x_5 = 1$ + + By doing $\nCr{n}{r}$ where n is the number of numbers and delimiters, and r is the number of delimiters, + we will get all combinations of $x_1 + x_2 + x_3 + x_4 + x_5 = 40$A + + In order to make it $x_1 + x_2 + x_3 + x_4 + x_5 \leq 40$, we will add a fifth delimiter, indicating the last block of unused numbers. + + $x_1 + x_2 + x_3 + x_4 + x_5 < 40 \Rightarrow x_1 + x_2 + x_3 + x_4 + x_5 \leq 39$ + + This leaves us with $\nCr{39 + 5}{5} = 1086008$ different combinations. + + \subexc{} + + In this case, we modify the problem by adjusting the inequality of $x_i$ like the following + + \begin{align*} + x_1 + x_2 + x_3 + x_4 + x_5 &< 40 \qquad &&x_i \geq -3 \\ + y_1 - 3 + y_2 - 3 + y_3 - 3 + y_4 - 3 + y_5 - 3 &< 40 &&(y_i - 3 = x) \\ + y_1 + y_2 + y_3 + y_4 + y_5 &< 40 + 5 \cdot 3 \\ + y_1 + y_2 + y_3 + y_4 + y_5 &< 55 + \end{align*} + + \[ (y_i - 3 = x) \Rightarrow (y_i - 3 \geq - 3) \Leftrightarrow (y_i \geq 0) \] + + With this information, we use the same way of solving as in \textbf{a)} + + \[\nCr{54 + 5}{5} = 5006386 \] + + \end{subexcs} + + \break{} + + \exc{} + + This is a Venn diagram of the set containing the elements that satisfy $\overline{c}_1$, $\overline{c}_2$ and $\overline{c}_3$. + + \includeDiagram[width=11cm, caption={$N(\overline{c}_2\overline{c}_3\overline{c}_4$)}]{diagrams/ex9_1.tex} + + The following diagrams show the terms of the RHS. + + \includeDiagram[width=11cm, caption={$N(c_1\overline{c}_2\overline{c}_3\overline{c}_4)$}]{diagrams/ex9_2.tex} + + \includeDiagram[width=11cm, caption={$N(\overline{c_1}\overline{c}_2\overline{c}_3\overline{c}_4)$}]{diagrams/ex9_3.tex} + + When we lay these two diagrams on top of each other, we can see that $N(c_1\overline{c}_2\overline{c}_3\overline{c}_4) + N(\overline{c}_1\overline{c}_2\overline{c}_3\overline{c}_4)$ is equal to $N(\overline{c}_2\overline{c}_3\overline{c}_4)$ + + \includeDiagram[width=11cm, caption={$N(c_1\overline{c}_2\overline{c}_3\overline{c}_4) + N(\overline{c}_1\overline{c}_2\overline{c}_3\overline{c}_4)$}]{diagrams/ex9_4.tex} + + \exc{} + + let + + $c_1 = 2 \mid n $ \\ + $c_2 = 3 \mid n $ \\ + $c_3 = 5 \mid n $ \\ + $c_4 = 7 \mid n $ + + \begin{align*} + N(\overline{c}_1\overline{c}_2\overline{c}_3c_4) &= N(c_4) - \left( N(c_1c_7) + N(c_2c_7) + N(c_3c_7) \right) \\ + &\quad + \left( N(c_1c_2c_4) + N(c_1c_3c_4) + N(c_2c_3c_4) \right) \\ + &\quad - N(c_1c_2c_3c_4) \\[2ex] + &= \left\lfloor \frac{2000}{7} \right\rfloor - \left( \left\lfloor \frac{2000}{2 \cdot 7} \right\rfloor + \left\lfloor \frac{2000}{3 \cdot 7} \right\rfloor + \left\lfloor \frac{2000}{5 \cdot 7} \right\rfloor \right) \\[2ex] + &\quad + \left( \left\lfloor \frac{2000}{2 \cdot 3 \cdot 7} \right\rfloor + \left\lfloor \frac{2000}{2 \cdot 5 \cdot 7} \right\rfloor + \left\lfloor \frac{2000}{3 \cdot 5 \cdot 7} \right\rfloor \right) \\[2ex] + &\quad - \left\lfloor \frac{2000}{2 \cdot 3 \cdot 5 \cdot 7} \right\rfloor \\[2ex] + &= 76 + \end{align*} + + + \end{excs} +\end{document} \ No newline at end of file diff --git a/exercise9/scripts/ex10.hs b/exercise9/scripts/ex10.hs new file mode 100644 index 0000000..d3a4c9d --- /dev/null +++ b/exercise9/scripts/ex10.hs @@ -0,0 +1,8 @@ +main :: IO () +main = print + $ length + $ [a | a <- [0..2000], + a `mod` 2 /= 0, + a `mod` 3 /= 0, + a `mod` 5 /= 0, + a `mod` 7 == 0] \ No newline at end of file