Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
\documentclass{article}
2
\usepackage[pdftex,active,tightpage]{preview}
3
\setlength\PreviewBorder{2mm}
4
5
\usepackage[utf8]{inputenc} % this is needed for umlauts
6
\usepackage[ngerman]{babel} % this is needed for umlauts
7
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
8
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
9
\usepackage{braket} % needed for \Set
10
\usepackage{algorithm,algpseudocode}
11
\renewcommand{\thealgorithm}{2} %disable numbers for algorithm
12
13
\begin{document}
14
\begin{preview}
15
\begin{algorithm}[H]
16
\begin{algorithmic}
17
\Require $G = (V, E)$ an undirected graph
18
\State $n \gets |V|$
19
\State Give all vertices an index $1 \leq i \leq n$ that defines an order
20
21
\For{$i \in 1, \dots, n$}
22
\State $v_i$.color $\gets 1$
23
\EndFor
24
\\
25
\For{$i \in 1, \dots, n$}
26
\State $possible \gets \Set{1, \dots, n}$
27
\For{$j \in i+1, \dots, n$}
28
\If{$\Set{v_i, v_j} \in E$}
29
\State $possible \gets possible \setminus \Set{v_j.\text{color}}$
30
\EndIf
31
\EndFor
32
\State $v_i$.color $\gets \min(possible)$
33
\EndFor
34
\end{algorithmic}
35
\caption{Find a vertex coloring for $G$}
36
\label{alg:vertexColoring}
37
\end{algorithm}
38
\end{preview}
39
\end{document}
40
41