Compare commits

..

11 Commits

Author SHA1 Message Date
RLogik
14f59eeb63 master > master: protokoll - woche 7 2021-11-26 17:30:07 +01:00
RLogik
a6cce9626c master > master: protokoll - woche 7 2021-11-26 14:47:24 +01:00
RLogik
8d726bf344 master > master: protokolle - woche 6+7 2021-11-25 18:52:38 +01:00
RLogik
04eecdb444 master > master: protokolle - Woche6 2021-11-22 08:49:26 +01:00
RLogik
60c47c20c5 master > master: protokoll - woche 5 (minor Anmerkung) 2021-11-13 18:30:32 +01:00
RLogik
89499f524f master > master: README.md 2021-11-13 16:55:57 +01:00
RLogik
e55d8708a7 master > master: protokoll - woche5 (minor) 2021-11-13 16:54:48 +01:00
RLogik
ea7dfc5bef master > mater: protokolle - woche4 + woche5 2021-11-13 09:01:35 +01:00
RLogik
18ece75b67 master > master: code - minor 2021-11-08 13:21:03 +01:00
RLogik
6541a5246d master > mater: code - nextGreaterElement, auxiliary methods entfernt 2021-11-07 18:56:49 +01:00
RLogik
3505401c7f master > master: minor 2021-11-07 18:52:46 +01:00
8 changed files with 79 additions and 86 deletions

View File

@@ -14,19 +14,19 @@ import (
* GLOBAL VARIABLES/CONSTANTS * GLOBAL VARIABLES/CONSTANTS
* ---------------------------------------------------------------- */ * ---------------------------------------------------------------- */
var _output_list [][2]int //
/* ---------------------------------------------------------------- * /* ---------------------------------------------------------------- *
* ALGORITHM next greater element * ALGORITHM next greater element
* ---------------------------------------------------------------- */ * ---------------------------------------------------------------- */
/* /*
Inputs: L = Liste von Zahlen, x = Zahl. Inputs: L = Liste von Zahlen.
Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element
*/ */
func NextGreaterElement(L []int) [][2]int { func NextGreaterElement(L []int) [][2]int {
clearOutput() output := [][2]int{}
S := stacks.CREATE() S := stacks.CREATE()
S.INIT() S.INIT()
@@ -41,9 +41,9 @@ func NextGreaterElement(L []int) [][2]int {
for !S.EMPTY() { // ACHTUNG: schreibe 'while' im Pseudocode, denn dies ist eine while-Schleife in golang for !S.EMPTY() { // ACHTUNG: schreibe 'while' im Pseudocode, denn dies ist eine while-Schleife in golang
element := S.TOP() element := S.TOP()
if element < nextElement { if element < nextElement {
logging.Debug("Stack S | %v; top Element > nextElement; ==> pop und Paar zum Output hinzufügen", S) // falls top Element < next Element, zum Output hinzufügen und vom Stack entfernen
// falls top Element < next Element, zum Output hinzufügen und vom Stack logging.Debug("Stack S | %v; top Element < nextElement; ==> pop und Paar zum Output hinzufügen", S)
addToOutput(element, nextElement) output = append(output, [2]int{element, nextElement})
S.POP() S.POP()
metrics.AddMovesCost() metrics.AddMovesCost()
logging.Debug("Stack S | %v", S) logging.Debug("Stack S | %v", S)
@@ -70,31 +70,12 @@ func NextGreaterElement(L []int) [][2]int {
for !S.EMPTY() { // ACHTUNG: schreibe 'while' im Pseudocode, denn dies ist eine while-Schleife in golang for !S.EMPTY() { // ACHTUNG: schreibe 'while' im Pseudocode, denn dies ist eine while-Schleife in golang
logging.Debug("Stack S | %v", S) logging.Debug("Stack S | %v", S)
element := S.TOP() element := S.TOP()
output = append(output, [2]int{element, -1})
S.POP() S.POP()
metrics.AddMovesCost() metrics.AddMovesCost()
addToOutput(element, -1)
} }
logging.Debug("Stack S | %v", S) logging.Debug("Stack S | %v", S)
return output()
}
/* ---------------------------------------------------------------- *
* AUXILIARY METHODS
* ---------------------------------------------------------------- */
func clearOutput() {
_output_list = [][2]int{}
}
func addToOutput(m int, n int) {
_output_list = append(_output_list, [2]int{m, n})
}
func output() [][2]int {
var output = make([][2]int, len(_output_list))
copy(output, _output_list)
clearOutput()
return output return output
} }

View File

@@ -24,7 +24,7 @@ type QueueInt struct {
} }
/* ---------------------------------------------------------------- * /* ---------------------------------------------------------------- *
* METHODS stacks * METHODS queues
* ---------------------------------------------------------------- */ * ---------------------------------------------------------------- */
func CREATE() QueueInt { func CREATE() QueueInt {

View File

@@ -16,7 +16,7 @@ from src.algorithms.methods import *;
# GLOBAL VARIABLES/CONSTANTS # GLOBAL VARIABLES/CONSTANTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_output_list: List[Tuple[int,int]] #
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CHECKS # CHECKS
@@ -37,10 +37,10 @@ def postChecks(L: List[int], **_):
@algorithmInfos(name='NextGreaterElement (with stacks)', outputnames=['pairs'], preChecks=preChecks, postChecks=postChecks) @algorithmInfos(name='NextGreaterElement (with stacks)', outputnames=['pairs'], preChecks=preChecks, postChecks=postChecks)
def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]: def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
''' '''
Inputs: L = Liste von Zahlen, x = Zahl. Inputs: L = Liste von Zahlen.
Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element
''' '''
clearOutput(); output = [];
S = Stack(); S = Stack();
S.INIT(); S.INIT();
@@ -55,10 +55,10 @@ def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
logDebug('Stack S | {S}'.format(S=S)); logDebug('Stack S | {S}'.format(S=S));
while not S.EMPTY(): while not S.EMPTY():
element = S.TOP(); element = S.TOP();
# falls element < next Element, zum Output hinzufügen # falls element < next Element, zum Output hinzufügen und vom Stack entfernen
if element < nextElement: if element < nextElement:
logDebug('Stack S | {S}; top Element > nextElement; ==> pop und Paar zum Output hinzufügen'.format(S=S)) logDebug('Stack S | {S}; top Element < nextElement; ==> pop und Paar zum Output hinzufügen'.format(S=S))
addToOutput(element, nextElement); output.append((element, nextElement));
S.POP(); S.POP();
AddMovesCost(); AddMovesCost();
logDebug('Stack S | {S}'.format(S=S)); logDebug('Stack S | {S}'.format(S=S));
@@ -85,27 +85,7 @@ def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
element = S.TOP(); element = S.TOP();
S.POP(); S.POP();
AddMovesCost(); AddMovesCost();
addToOutput(element, -1); output.append((element, -1));
logDebug('Stack S | {S}'.format(S=S)) logDebug('Stack S | {S}'.format(S=S))
return output(); return output;
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# AUXILIARY METHODS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def clearOutput():
global _output_list;
_output_list = [];
return;
def addToOutput(m: int, n: int):
global _output_list;
_output_list.append((m, n))
return;
def output() -> List[Tuple[int, int]]:
global _output_list;
output = _output_list[:] # erstelle Kopie
clearOutput()
return output

View File

@@ -6,11 +6,11 @@ Inhaltsverzeichnis
- [Vorlesungswoche 2](./woche2.md) - [Vorlesungswoche 2](./woche2.md)
- [Vorlesungswoche 3](./woche3.md) - [Vorlesungswoche 3](./woche3.md)
- [Vorlesungswoche 4](./woche4.md) - [Vorlesungswoche 4](./woche4.md)
- [Vorlesungswoche 5](./woche4.md) - [Vorlesungswoche 5](./woche5.md)
- [Vorlesungswoche 6](./woche4.md) - [Vorlesungswoche 6](./woche6.md)
- [Vorlesungswoche 7](./woche4.md) - [Vorlesungswoche 7](./woche7.md)
- [Vorlesungswoche 8](./woche4.md) - [Vorlesungswoche 8](./woche8.md)
- [Vorlesungswoche 9](./woche4.md) - [Vorlesungswoche 9](./woche9.md)
- [Vorlesungswoche 10](./woche10.md) - [Vorlesungswoche 10](./woche10.md)
- [Vorlesungswoche 11](./woche11.md) - [Vorlesungswoche 11](./woche11.md)
- [Vorlesungswoche 12](./woche12.md) - [Vorlesungswoche 12](./woche12.md)

View File

@@ -16,7 +16,8 @@
## Nächste Woche ## ## Nächste Woche ##
- ab selbstorganisierende Listen und Sortierungsalgorithmen - Sortierungsalgorithmen
- Bäume
### TODOs (Studierende) ### ### TODOs (Studierende) ###

View File

@@ -2,13 +2,41 @@
## Agenda ## ## Agenda ##
- [ ] - Gruppe 1
- [ ] - [x] Alle Sortierverfahren durchgegangen; argumentierte, wieso die Algorithmen korrekt sind.
- [x] Bäume und Listendarstellung von **fast vollständige binäre Bäume**.
- [x] Max-Heap-Eigenschaft (MHE).
- [x] Theorem: folgende Aussagen sind äquivalent
- T hat MHE
- (Definition) alle Unterbäume von T haben Max in Wurzel, d. h.
für alle Knoten, e, gilt
```
value(e) ≥ max{value(e') | e' Unterhalb von e in T}
```
- für alle Knoten, e, gilt
```
value(e) ≥ max{value(e') | e' Tochterknoten von e in T}
```
- L[i] = L[2i+1] und L[i] = L[2i+2] (jeweils solange Indexes in Listendarstellung L, wobei L = Listendarstellung von Baum T).
- Gruppe 2
- [x] Alle Sortierverfahren durchgegangen; argumentierte, wieso die Algorithmen korrekt sind.
(Etwas ausführlicher, weil MHE, usw. schon in der Übung diskutiert wurden.)
**Anmerkung.**
Bei Quicksort konnten wir sehen, dass die Zeit- (und Satzbewegungs!) komplexität durch
$C(n) = 2C(n/2) + Θ(n)$ gegeben ist (warum diese Koeffizienten, warum Θ(n)?).
</br>
Laut **Mastertheorem** gilt also $C(n) ∈ Θ(n·log(n))$ (warum?).
</br>
Das ist aber der Worst-case.
</br>
Wie verhält sich das beim Average-Case ($C_{av}(n)$)?
## Nächste Woche ## ## Nächste Woche ##
- - Ab VL5 + Blatt 6.
### TODOs (Studierende) ### ### TODOs (Studierende) ###
- - VL-Inhalte aus Wochen 4 + 5 durchgehen
- freiwillige ÜB 5 + Pflichtserie 3.

View File

@@ -2,13 +2,10 @@
## Agenda ## ## Agenda ##
- [ ] - [x] Mergesort, inkl. Pseudo-Code
- [ ] - [x] natürliches Mergesort, inkl. Aspekte
- [x] k-Wege Mergesort
## Nächste Woche ##
-
### TODOs (Studierende) ### ### TODOs (Studierende) ###
- - weiter an Pflichtserie3 arbeiten.

View File

@@ -2,13 +2,19 @@
## Agenda ## ## Agenda ##
- [ ] - [x] Orga: nochmalige Abstimmung der Studierenden über Präsenz v. Digital
- [ ] ---> überwiegende Mehrheit für weiteren Präsenzbetrieb.
## Nächste Woche ## Aspekte und Berechnungen mit binären Suchbäumen
- - Aspekte, insbesondere *ausgeglichen*.
- Motivation: wieso wollen wir *ausgeglichene* Suchbäume?
- Optimierung der Tiefe h vis-á-vis Anzahl der Knoten, n.
- Suchalgorithmus im Suchbaum
- welche Verhältnisse müssen zw. den Knoten gelten?
- Ansatz bei INSERT und ROTATE, um *ausgeglichenen* Baum
mit passenden Verhältnissen zw. Knoten zu erzeugen.
### TODOs (Studierende) ### ### TODOs (Studierende) ###
- - weiter an Pflichtserie3 arbeiten und vor der Frist abgeben.