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
12
\begin{document}
13
\begin{preview}
14
\begin{algorithm}[H]
15
\begin{algorithmic}
16
\Require $G = (V, E)$ an undirected graph
17
\State $n \gets |V|$
18
\State Give all vertices an index $1 \leq i \leq n$ that defines an order
19
20
\For{$i \in 1, \dots, n$}
21
\State $v_i$.color $\gets 1$
22
\EndFor
23
\\
24
\For{$i \in 1, \dots, n$}
25
\For{$j \in i+1, \dots, n$}
26
\If{$\Set{v_i, v_j} \in E \land v_i.\text{color} = v_j.\text{color}$}
27
\State $v_j.color \gets v_j.color + 1$
28
\EndIf
29
\EndFor
30
\EndFor
31
\end{algorithmic}
32
\caption{Find a vertex coloring for $G$}
33
\label{alg:vertexColoring}
34
\end{algorithm}
35
\end{preview}
36
\end{document}
37
38