Compare commits
4 Commits
c5b93eb3e3
...
71d87423fe
Author | SHA1 | Date | |
---|---|---|---|
71d87423fe | |||
379d660c89 | |||
e65b5dc51b | |||
8a858ad17c |
2
.gitignore
vendored
2
.gitignore
vendored
@ -20,6 +20,8 @@
|
||||
!/protocol/woche*.md
|
||||
|
||||
!/code
|
||||
!/code/**/
|
||||
!/code/**/*.py
|
||||
|
||||
################################################################
|
||||
# ARTEFACTS
|
||||
|
18
README.md
18
README.md
@ -22,3 +22,21 @@ In diesem Repository findet man:
|
||||
|
||||
- ≥ 50% der Punkte aus den 6 Pflichtserien sollen geschafft werden.
|
||||
- _nur digitale Abgabe_!
|
||||
|
||||
## Code ##
|
||||
|
||||
Im Unterordner [`code`](./code) kann man ein Python-Projekt finden, in dem verschiedene Algorithmen implementiert werden.
|
||||
Man kann gerne den Code benutzen, in einer eigenen Repository verändern,
|
||||
und mit den in dem Kurs präsentierten Algorithmen herumexperimentieren.
|
||||
|
||||
Um den Python Code auszuführen, bspw. im Bash:
|
||||
```bash
|
||||
python3 code/main.py; # linux, OSX
|
||||
py -3 code/main.py; # Windows
|
||||
```
|
||||
Oder man erstelle einen bash Skript wie `run.sh`, trage die Befehle da ein und führe
|
||||
```bash
|
||||
chmod +x run.sh; # nur einmalig nötig
|
||||
./run.sh
|
||||
```
|
||||
aus.
|
||||
|
0
code/__init__.py
Normal file
0
code/__init__.py
Normal file
0
code/local/__init__.py
Normal file
0
code/local/__init__.py
Normal file
9
code/local/maths.py
Normal file
9
code/local/maths.py
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
import math;
|
||||
import random;
|
9
code/local/misc.py
Normal file
9
code/local/misc.py
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
import re;
|
||||
from textwrap import dedent;
|
14
code/local/system.py
Normal file
14
code/local/system.py
Normal file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
import os;
|
||||
import sys;
|
||||
|
||||
import pathlib;
|
||||
import platform;
|
||||
import shutil;
|
||||
import subprocess;
|
19
code/local/typing.py
Normal file
19
code/local/typing.py
Normal file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from types import TracebackType;
|
||||
|
||||
from typing import Any;
|
||||
from typing import Callable;
|
||||
from typing import Dict;
|
||||
from typing import Generator;
|
||||
from typing import Generic;
|
||||
from typing import List;
|
||||
from typing import Tuple;
|
||||
from typing import Type;
|
||||
from typing import TypeVar;
|
||||
from typing import Union;
|
49
code/main.py
Normal file
49
code/main.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# IMPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
import os;
|
||||
import sys;
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
||||
|
||||
from code.search.exports import *;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# GLOBAL VARIABLES/CONSTANTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
#
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# MAIN PROCESS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def main():
|
||||
goThroughCases();
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# SECONDARY PROCESSES
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def goThroughCases():
|
||||
## Hier Fälle einfügen:
|
||||
## Case 1:
|
||||
L = [1,3,5,7,11,13,17,19,23];
|
||||
u = 0;
|
||||
v = len(L) - 1;
|
||||
x = 13;
|
||||
p = AlgoInterpol(L, u, v, x);
|
||||
print('Ausführung des Interplationsalgorithmus:', p, L[p] if p >= 0 else None);
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXECUTE CODE
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
if __name__ == '__main__':
|
||||
main();
|
0
code/search/__init__.py
Normal file
0
code/search/__init__.py
Normal file
8
code/search/exports.py
Normal file
8
code/search/exports.py
Normal file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from code.search.methods import AlgoInterpol;
|
40
code/search/methods.py
Normal file
40
code/search/methods.py
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# IMPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from local.maths import *;
|
||||
from local.typing import *;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# GLOBAL VARIABLES/CONSTANTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
#
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# ALGORITHM
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def AlgoInterpol(L: List[int], u: int, v: int, x: int) -> int:
|
||||
if not(L[u] <= x and x <= L[v]):
|
||||
print('out of bounds!')
|
||||
return -1;
|
||||
p = getSuchposition(L, u, v, x);
|
||||
print('Interpolatiert von u={u}, v={v} -> p = {p}.'.format(u=u, v=v, p=p));
|
||||
if L[p] == x:
|
||||
print('gefunden!');
|
||||
return p;
|
||||
elif x > L[p]:
|
||||
print('x > L[p]');
|
||||
return AlgoInterpol(L, p+1, v, x);
|
||||
else:
|
||||
print('x < L[p]');
|
||||
return AlgoInterpol(L, u, p-1, x);
|
||||
|
||||
def getSuchposition(L: List[int], u: int, v: int, x: int) -> int:
|
||||
r = (x - L[u])/(L[v]-L[u]);
|
||||
p = math.floor(u + r*(v-u))
|
||||
return p;
|
@ -2,13 +2,40 @@
|
||||
|
||||
## Agenda ##
|
||||
|
||||
- [ ]
|
||||
- [ ]
|
||||
- [x] Wdh: Laufzeitberechnung
|
||||
- Verschachtelte Blöcke
|
||||
- Blöcke hintereinander
|
||||
- Rekursion ---> Masterthm
|
||||
- [x] Big-Oh Notation
|
||||
- Bestimmung von Klassen
|
||||
- Vergleiche zw. Klassen
|
||||
- [x] Masterthm
|
||||
- Größen: a, b, g
|
||||
- Wie lässt sich T(n/b) definieren, wenn n/b nicht ganzzahlig ist?
|
||||
- Man benutze Floor im Masterthm:
|
||||
```text
|
||||
Korrekte Variante: T(n) = a·T(floor(n/b)) + g(n)
|
||||
```
|
||||
- Bemerkung: man kann einen Trick verwenden, um T und g von Funktionen ℕ ⟶ ℕ
|
||||
auf Funktionen ℝ⁺ ⟶ ℕ zu erweitern, nämlich
|
||||
```text
|
||||
Setze T(x) := T(floor(x)) für alle x ∈ ℝ⁺
|
||||
Setze g(x) := g(floor(x)) für alle x ∈ ℝ⁺
|
||||
```
|
||||
und kann damit den Ausdruck im Masterthm wieder vereinfachen auf:
|
||||
```text
|
||||
T(n) = a·T(n/b) + g(n)
|
||||
```
|
||||
und den Satz ohne Probleme beweisen.
|
||||
- [ ] Suchalgorithmen
|
||||
- (diese Woche nicht dazu gekommen)
|
||||
|
||||
|
||||
## Nächste Woche ##
|
||||
|
||||
-
|
||||
- ab Suchalgorithmen
|
||||
|
||||
### TODOs (Studierende) ###
|
||||
|
||||
-
|
||||
- VL-Inhalte aus Wochen 1–2 durchgehen
|
||||
- Empfohlen: jeden Suchalgorithmus verstehen und ausprobieren (entweder per Hand oder durch Implementierung)
|
||||
|
Loading…
x
Reference in New Issue
Block a user