aboutsummaryrefslogtreecommitdiff
path: root/Info/11/MUG_SWG_SG/1/Pfade/slides.md
blob: dcd2950abc115510aea328d6257abb1aa304808e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
---
header-includes: |
    \usepackage{booktabs}
    \newcommand{\graph}{
      \begin{tikzpicture}
      \node[fill=red, circle, minimum size=0.2cm] (ts) {};
      \node[above=0.1cm of ts] {Traunstein};
      
      \node[fill=red, circle, minimum size=0.2cm] (ib) at (-2, -1) {};
      \node[xshift=-0.3cm, above=0.1cm of ib] {Innsbruck};
      
      \node[fill=red, circle, minimum size=0.2cm] (ms) at (1, -2) {};
      \node[right=0.1cm of ms] {Millstadt};
      
      \draw (ts) -- node[fill=yellow!30] {138} (ib);
      \draw (ts) -- node[fill=yellow!30] {211} (ms);
      
      \node[fill=red, circle, minimum size=0.2cm] (ic) at (-1, -2.5) {};
      \node[left=0cm of ic, yshift=-0.2cm] {Innichen};
      
      \draw (ib) -- node[fill=yellow!30] {139} (ic);
      \draw (ms) -- node[fill=yellow!30] {120} (ic);
      
      \node[fill=red, circle, minimum size=0.2cm] (vd) at (0, -4) {};
      \node[right=0.1cm of vd] {Venedig};
      \draw (ic) -- node[fill=yellow!30] {197} (vd);
      \draw (ms) -- node[fill=yellow!30] {278} (vd);
      \end{tikzpicture}
    }
---

## Wdh - Sortieren {.standout}

Sortieren

## Wdh - Sortieren

Beschreibe einen Algorithmus damit ich 5 Spielkarten der Größe nach sortieren kann.

\pause
### Algorithmen (Auswahl)

- Insertionsort - [wikipedia.org/wiki/Insertionsort](https://de.wikipedia.org/wiki/Insertionsort)
- Selectionsort - [wikipedia.org/wiki/Selectionsort](https://de.wikipedia.org/wiki/Selectionsort)
- [Simplesort]{.underline} - [wikipedia.org/wiki/Simplesort](https://de.wikipedia.org/wiki/Simplesort)
- Bubblesort - [wikipedia.org/wiki/Bubblesort](https://de.wikipedia.org/wiki/Bubblesort)
- Mergesort - [wikipedia.org/wiki/Mergesort](https://de.wikipedia.org/wiki/Mergesort)
- Quicksort - [wikipedia.org/wiki/Quicksort](https://de.wikipedia.org/wiki/Quicksort)
- Bogosort - [wikipedia.org/wiki/Bogosort](https://de.wikipedia.org/wiki/Bogosort)
- ...  - [wikipedia.org/wiki/Sortierverfahren](https://de.wikipedia.org/wiki/Sortierverfahren)

## Wdh - Simplesort

Vereinfachung des Selectionsorts.

\pause
### **Algortihmus**

```
Wiederhole für jeden Index → zielIndex
  // KOMMENTAR: Suche kleinere Elemente im nachfolgenden, noch unsortieren Bereich:
  Wiederhole für jeden größeren Index → pruefIndex
    Falls Eintrag an preufIndex < Eintrag an zielIndex
      Vertausche Eintrag an pruefIndex mit dem Eintrag an zielIndex
```

\pause
### \faIcon{desktop} Arbeitsauftrag - Simplesort in `Snap!`

Implementiere den Simplesort Algorithmus in einer Snap! Methode

## \faIcon{chalkboard-teacher} Lösung - Simplesort in `Snap!`

![](img/simplesort_snap.png){.center height=85%}

## Radtour nach Venedig

::: columns
:::: {.column width=50%}
Für die kommenden Sommerferien plant ihr eine Radtour durch die Alpen nach \boldred{Venedig}.
\vspace{1cm}

\pause

Als Startpunkt habt ihr euch \boldred{Traunstein} ausgesucht.
::::

:::: {.column width=50%}
\graph
::::
:::

## Radtour nach Venedig

::: columns
:::: {.column width=50%}
\vspace{2cm}
Wie finden wir den kürzesten Weg von Traunstein nach Venedig?
::::

:::: {.column width=50%}
\graph
::::
:::

## Dijkstra Algortihmus

Eine Möglichkeit \boldred{effizient} den kürzesten Weg zwischen zwei Punkten zu finden ist der Algorithmus des niederländischen Informatikers Dijkstra.

Dazu benötigen wir zu erst eine Tabelle aller Orte mit den vier Spalten:  
**Ort, kommt von, Distanz zum Start, bearbeitet**

::: columns
:::: {.column width=60%}
\begin{tabular}{l | l | l | l}
Ort & kommt von & Distanz zum Start & bearbeitet \\
\toprule
Traunstein & & 0 & \\
\hline
Innsbruck & & $\infty$ & \\
\hline
Innichen & & $\infty$ & \\
\hline
Millstatt & & $\infty$ & \\
\hline
Venedig & & $\infty$ & \\
\end{tabular}
::::

:::: {.column width=40%}
\hspace{0.3cm} \scalebox{0.8}{\graph}
::::
:::


## Dijkstra Algortihmus Start

Zuerst tragen wir alle benachbarten Orte vom Start und ihre Distanzen ein und vermerken den Start als \textbf{bearbeitet}.

::: columns
:::: {.column width=60%}
\begin{tabularx}{\textwidth}{X | X | X | X}
Ort & kommt von & Distanz zum Start & bearbeitet \\
\toprule
Traunstein & & 0 & \cellcolor{green!20} X \\
\hline
\rowcolor{blue!10} Innsbruck & Traunstein & 138 & \\
\hline
Innichen & & $\infty$ & \\
\hline
\rowcolor{blue!10} Millstatt & Traunstein & 211 & \\
\hline
Venedig & & $\infty$ & \\
\end{tabularx}
::::

:::: {.column width=40%}
\hspace{0.3cm} \scalebox{0.8}{\graph}
::::
:::

## Dijkstra Algortihmus Fortsetzung

Wir wählen den \boldred{nicht bearbeiteten} Ort mit der \boldred{kürzesten} Distanz zum Start.  

\only<1>{\phantom{Setzen in auf \textbf{bearbeitet}.}}
\only<2->{Setzen in auf \textbf{bearbeitet}.}

\only<-2>{\phantom{Von dem gewählten Ort bestimmen wir alle Distanzen zum Start und aktualisieren Einträge für die wir einen kürzeren Weg gefunden haben.}}
\only<3->{Von dem gewählten Ort bestimmen wir alle Distanzen zum Start und aktualisieren Einträge für die wir einen kürzeren Weg gefunden haben.}

::: columns
:::: {.column width=60%}
\only<-5>{
\begin{tabularx}{\textwidth}{X | X | X | X}
Ort & kommt von & Distanz zum Start & bearbeitet \\
\toprule
Traunstein & & 0 & X \\
\hline
\rowcolor{red!20} Innsbruck & Traunstein & 138 & \only<2->{\cellcolor{green!20}} \only<2->{X} \only<-2>{\\ \hline}
\only<3->{\\ \hline \rowcolor{blue!10}} Innichen & \only<4->{Innsbruck} & \only<-3>{$\infty$}\only<4->{277} & \\
\hline
Millstatt & Traunstein & 211 & \\
\hline
Venedig & & $\infty$ & \\
\end{tabularx}
}
\only<6-8>{
\begin{tabularx}{\textwidth}{X | X | X | X}
Ort & kommt von & Distanz zum Start & bearbeitet \\
\toprule
Traunstein & & 0 & X \\
\hline
Innsbruck & Traunstein & 138 & X \\
\hline
Innichen & Innsbruck & \only<-3>{$\infty$}\only<4->{277} & \\
\hline
\rowcolor{red!20} Millstatt & Traunstein & 211 & \only<7->{\cellcolor{green!20}} \only<7->{X} \only<-7>{\\ \hline}
\only<8->{\\ \hline \rowcolor{blue!10}} Venedig & \only<8->{Millstadt} & \only<-7>{$\infty$}\only<8>{498} & \\
\end{tabularx}
}
\only<9-10>{
\begin{tabularx}{\textwidth}{X | X | X | X}
Ort & kommt von & Distanz zum Start & bearbeitet \\
\toprule
Traunstein & & 0 & X \\
\hline
Innsbruck & Traunstein & 138 & X \\
\hline
\rowcolor{red!20} Innichen & Innsbruck & 277 & \only<7->{\cellcolor{green!20} X} \\
\hline
Millstatt & Traunstein & 211 & X \only<-9>{\\ \hline}
\only<10->{\\ \hline \rowcolor{blue!10}} Venedig & \only<9->{Innichen} & \only<-9>{498}\only<10>{\textbf{474}} & \\
\end{tabularx}
}
\only<11->{
\begin{tabularx}{\textwidth}{X | X | X | X}
Ort & kommt von & Distanz zum Start & bearbeitet \\
\toprule
Traunstein & & 0 & X \\
\hline
Innsbruck & Traunstein & 138 & X \\
\hline
Innichen & Innsbruck & 277 & X \\
\hline
Millstatt & Traunstein & 211 & X \\
\hline
\rowcolor{red!20} Venedig & Innichen & 474 & \only<11->{\cellcolor{green!20} X}\\
\end{tabularx}
}
::::

:::: {.column width=40%}
\hspace{0.3cm} \scalebox{0.8}{\graph}
::::
:::

## Dijkstra Algortihmus Ende

Der kürzeste Weg zu einem Ort wurde gefunden sobald dieser als bearbeitet markiert ist.
\begin{tabularx}{\textwidth}{X | X | X | X}
Ort & kommt von & Distanz zum Start & bearbeitet \\
\toprule
Traunstein & & 0 & X \\
\hline
Innsbruck & Traunstein & 138 & X \\
\hline
Innichen & Innsbruck & 277 & X \\
\hline
Millstatt & Traunstein & 211 & X \\
\hline
\rowcolor{red!20} Venedig & Innichen & 474 & X\\
\end{tabularx}

Der Weg nach Venedig lässt sich aus der Tabelle ablesen:  
**Venedig < Innichen < Innsbruck < Traunstein**

## \faIcon{pencil-alt} Arbeitsauftrag - Dijkstra

::: columns
:::: {.column width=70%}
\begin{enumerate}[a)]
\item Ermittle alle möglichen Wege von A nach D mit ihren Längen.
\item Ermittle den kürzesten Weg von A nach D mit dem Dijkstra-Algortihmus.
\item Vergleiche den Aufwand von \textbf{a)} und \textbf{b)}. Warum wird der Dijkstra-Algortihmus erst bei vielen Knoten überlegen sein?
\end{enumerate}
::::

:::: {.column width=30%}
\begin{tikzpicture}
\node[circle, fill=blue!10] (a) {A};
\node[circle, fill=blue!10, yshift=1cm, right=1cm of a] (b) {B};
\node[circle, fill=blue!10, right=2cm of a] (d) {D};
\node[circle, fill=blue!10, yshift=-1cm, right=1cm of a] (c) {C};

\draw (a) -- node[fill=bg] {3} (b);
\draw (b) -- node[fill=bg] {2} (d);
\draw (d) -- node[fill=bg] {5} (c);
\draw (c) -- node[fill=bg] {1} (a);
\draw (c) -- node[fill=bg, above] {3} (b);
\draw (a) -- node[fill=bg] {7} (d);
\end{tikzpicture}
::::
:::