diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-04-19 15:21:02 +0200 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-04-19 15:21:02 +0200 |
| commit | a61b998270e8f955c603de96775e072a555f735d (patch) | |
| tree | c89c8cd2ecab33eecc4fefb4a8089a8df208d17a /ss2016 | |
| parent | 6e70a46771d3b28edc80a88de22b98df47147dc1 (diff) | |
| download | uni-a61b998270e8f955c603de96775e072a555f735d.tar uni-a61b998270e8f955c603de96775e072a555f735d.tar.gz uni-a61b998270e8f955c603de96775e072a555f735d.tar.bz2 uni-a61b998270e8f955c603de96775e072a555f735d.tar.xz uni-a61b998270e8f955c603de96775e072a555f735d.zip | |
AlgoDat 01
Diffstat (limited to 'ss2016')
| -rw-r--r-- | ss2016/algodat/01/H1-1.md | 32 | ||||
| -rw-r--r-- | ss2016/algodat/01/H1-2.md | 10 | ||||
| -rw-r--r-- | ss2016/algodat/01/MergeSort.java | 48 | ||||
| -rw-r--r-- | ss2016/algodat/01/manifest | 3 |
4 files changed, 93 insertions, 0 deletions
diff --git a/ss2016/algodat/01/H1-1.md b/ss2016/algodat/01/H1-1.md new file mode 100644 index 0000000..d93f86c --- /dev/null +++ b/ss2016/algodat/01/H1-1.md | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | a) | ||
| 2 | |||
| 3 | \begin{algorithmic}[1] | ||
| 4 | \FORALL{entries $e$ on the shopping list} | ||
| 5 | \STATE{$c \leftarrow \text{category of $e$}$} | ||
| 6 | \STATE{Go to shelf $s$ labeled $c$} | ||
| 7 | \FORALL{products $p$ on $s$} \label{alg:loopstart} | ||
| 8 | \IF{$p$ matches $e$} | ||
| 9 | \STATE{add $p$ to shopping basket} | ||
| 10 | \STATE{break out of loop started in line \ref{alg:loopstart}} | ||
| 11 | \ENDIF | ||
| 12 | \ENDFOR | ||
| 13 | \ENDFOR | ||
| 14 | \end{algorithmic} | ||
| 15 | |||
| 16 | b) | ||
| 17 | |||
| 18 | \begin{algorithmic}[1] | ||
| 19 | \WHILE{not at destination within forest} | ||
| 20 | \STATE{break crumb of bread} | ||
| 21 | \STATE{drop crumb} | ||
| 22 | \STATE{take step towards destination} | ||
| 23 | \ENDWHILE | ||
| 24 | \WHILE{not out of forest} | ||
| 25 | \IF{we see at least one crumb} | ||
| 26 | \STATE{Go to the closest one} | ||
| 27 | \STATE{Pick it up} | ||
| 28 | \ELSE | ||
| 29 | \STATE{Get eaten by a witch} | ||
| 30 | \ENDIF | ||
| 31 | \ENDWHILE | ||
| 32 | \end{algorithmic} | ||
diff --git a/ss2016/algodat/01/H1-2.md b/ss2016/algodat/01/H1-2.md new file mode 100644 index 0000000..7a50a2a --- /dev/null +++ b/ss2016/algodat/01/H1-2.md | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | \begin{align*} | ||
| 2 | L &= \lim_{n \to \infty} \frac{n \cdot 2^n}{n^n} \\ | ||
| 3 | &= \lim_{n \to \infty} \frac{2^{\log_2(n) + n}}{2^{\log_2(n) \cdot n}} \\ | ||
| 4 | &= \lim_{n \to \infty} 2^{n + \log_2(n) - \log_2(n) \cdot n} \\ | ||
| 5 | n + \log(n) - \log(n) \cdot n &\leq 2n - \log(n) \cdot n \\ | ||
| 6 | &= (2 - \log(n)) \cdot n \xrightarrow{n \to \infty} - \infty \\ | ||
| 7 | L &= 0 | ||
| 8 | \end{align*} | ||
| 9 | |||
| 10 | $n \cdot 2^n$ und $n^n$ sind also sogar in der selben Komplexitätsklasse. | ||
diff --git a/ss2016/algodat/01/MergeSort.java b/ss2016/algodat/01/MergeSort.java new file mode 100644 index 0000000..97f7cfa --- /dev/null +++ b/ss2016/algodat/01/MergeSort.java | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | import java.util.*; | ||
| 2 | |||
| 3 | class MergeSort { | ||
| 4 | public static void mergeSort(int[] a, int from, int to) { | ||
| 5 | if (from >= to) | ||
| 6 | return; | ||
| 7 | |||
| 8 | int mid = (from + to) / 2; | ||
| 9 | mergeSort(a, from, mid); | ||
| 10 | mergeSort(a, mid + 1, to); | ||
| 11 | merge(a, from, mid, to); | ||
| 12 | } | ||
| 13 | |||
| 14 | public static void merge(int[] a, int from, int mid, int to) { | ||
| 15 | int[] b = new int[to - from + 1]; | ||
| 16 | |||
| 17 | int i, j; | ||
| 18 | i = from; | ||
| 19 | j = mid + 1; | ||
| 20 | |||
| 21 | for (int k = 0; k < b.length; k++) { | ||
| 22 | if (j > to || (i <= mid && a[i] < a[j])) { | ||
| 23 | b[k] = a[i]; | ||
| 24 | i++; | ||
| 25 | } else { | ||
| 26 | b[k] = a[j]; | ||
| 27 | j++; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | for (int k = 0; k < b.length; k++) { | ||
| 32 | a[k + from] = b[k]; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | public static void mergeSort(int[] a) { | ||
| 37 | mergeSort(a, 0, a.length - 1); | ||
| 38 | } | ||
| 39 | |||
| 40 | public static void main (String[] argv) { | ||
| 41 | int[] a = new int[argv.length]; | ||
| 42 | for (int i = 0; i < argv.length; i++) | ||
| 43 | a[i] = Integer.parseInt(argv[i]); | ||
| 44 | |||
| 45 | mergeSort(a); | ||
| 46 | System.out.println(Arrays.toString(a)); | ||
| 47 | } | ||
| 48 | } | ||
diff --git a/ss2016/algodat/01/manifest b/ss2016/algodat/01/manifest new file mode 100644 index 0000000..d76cd81 --- /dev/null +++ b/ss2016/algodat/01/manifest | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | H1-1.pdf | ||
| 2 | H1-2.pdf | ||
| 3 | MergeSort.java \ No newline at end of file | ||
