Lecture 1
This commit is contained in:
parent
a5e104b9fc
commit
61208603d1
14
README.md
14
README.md
@ -0,0 +1,14 @@
|
|||||||
|
## Algorithmen und Datenstrukturen im SoSe 24
|
||||||
|
### Prof. Dr. Oliver Hofmann
|
||||||
|
|
||||||
|
|
||||||
|
## Dateistruktur
|
||||||
|
### Oberste Ebene
|
||||||
|
- `README.md`: Diese Datei
|
||||||
|
- seq0.txt bis seq3.txt: Sequenzen für die Aufgaben
|
||||||
|
|
||||||
|
### algodat
|
||||||
|
- `foundation.py`: Python-Modul mit Klassen und Modulen zur Messung von Zugriffen
|
||||||
|
|
||||||
|
### lec01_alg
|
||||||
|
- Beispiele aus der ersten Vorlesung
|
@ -1,4 +1,5 @@
|
|||||||
class AlgoDatValue:
|
class AlgoDatValue:
|
||||||
|
"""A class representing a value with statistics."""
|
||||||
|
|
||||||
memory = 0
|
memory = 0
|
||||||
read = 0
|
read = 0
|
||||||
@ -12,7 +13,6 @@ class AlgoDatValue:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def summary():
|
def summary():
|
||||||
print("*** Summary ***")
|
|
||||||
print(f"Memory: {AlgoDatValue.memory}")
|
print(f"Memory: {AlgoDatValue.memory}")
|
||||||
print(f"Read: {AlgoDatValue.read}")
|
print(f"Read: {AlgoDatValue.read}")
|
||||||
print(f"Write: {AlgoDatValue.write}")
|
print(f"Write: {AlgoDatValue.write}")
|
||||||
@ -23,7 +23,6 @@ class AlgoDatValue:
|
|||||||
print(f"Div: {AlgoDatValue.div_operation}")
|
print(f"Div: {AlgoDatValue.div_operation}")
|
||||||
print(f"Bit: {AlgoDatValue.bit_operation}")
|
print(f"Bit: {AlgoDatValue.bit_operation}")
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
AlgoDatValue.memory += 1
|
AlgoDatValue.memory += 1
|
||||||
AlgoDatValue.write += 1
|
AlgoDatValue.write += 1
|
||||||
@ -228,8 +227,14 @@ class AlgoDatValue:
|
|||||||
def __round__(self, n=0):
|
def __round__(self, n=0):
|
||||||
return round(self.value, n)
|
return round(self.value, n)
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
if name == "value":
|
||||||
|
AlgoDatValue.write += 1
|
||||||
|
self.__dict__[name] = value
|
||||||
|
|
||||||
|
|
||||||
class AlgoDatArray:
|
class AlgoDatArray:
|
||||||
|
"""A class representing an array of AlgoDatValue objects."""
|
||||||
|
|
||||||
def __init__(self, size):
|
def __init__(self, size):
|
||||||
self.size = size
|
self.size = size
|
||||||
@ -263,10 +268,49 @@ class AlgoDatArray:
|
|||||||
self.array[index] = value
|
self.array[index] = value
|
||||||
|
|
||||||
|
|
||||||
def ReadIntSequence(filename):
|
class MinusInf:
|
||||||
|
"""A class representing negative infinity."""
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __ge__(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class Inf:
|
||||||
|
"""A class representing positive infinity."""
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __ge__(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def read_int_sequence(filename: str) -> AlgoDatArray:
|
||||||
|
"""Reads a sequence of integers from a file and returns an AlgoDatArray object."""
|
||||||
with open(filename, "r") as file:
|
with open(filename, "r") as file:
|
||||||
l = list(map(int, file.read().split()))
|
l = list(map(int, file.read().split()))
|
||||||
a = AlgoDatArray(len(l))
|
a = AlgoDatArray(len(l))
|
||||||
for i in range(len(l)):
|
for i in range(len(l)):
|
||||||
a.set(i, AlgoDatValue(l[i]))
|
a.set(i, AlgoDatValue(l[i]))
|
||||||
return a
|
return a
|
||||||
|
100
seq1.txt
Normal file
100
seq1.txt
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
56
|
||||||
|
13
|
||||||
|
97
|
||||||
|
14
|
||||||
|
5
|
||||||
|
40
|
||||||
|
33
|
||||||
|
20
|
||||||
|
51
|
||||||
|
98
|
||||||
|
52
|
||||||
|
89
|
||||||
|
31
|
||||||
|
33
|
||||||
|
47
|
||||||
|
59
|
||||||
|
47
|
||||||
|
75
|
||||||
|
11
|
||||||
|
39
|
||||||
|
0
|
||||||
|
79
|
||||||
|
33
|
||||||
|
57
|
||||||
|
5
|
||||||
|
1
|
||||||
|
28
|
||||||
|
87
|
||||||
|
77
|
||||||
|
54
|
||||||
|
35
|
||||||
|
21
|
||||||
|
24
|
||||||
|
97
|
||||||
|
96
|
||||||
|
94
|
||||||
|
6
|
||||||
|
31
|
||||||
|
-45
|
||||||
|
53
|
||||||
|
-98
|
||||||
|
-44
|
||||||
|
85
|
||||||
|
-76
|
||||||
|
-48
|
||||||
|
-90
|
||||||
|
-99
|
||||||
|
47
|
||||||
|
-11
|
||||||
|
16
|
||||||
|
-98
|
||||||
|
98
|
||||||
|
-23
|
||||||
|
57
|
||||||
|
27
|
||||||
|
-35
|
||||||
|
23
|
||||||
|
65
|
||||||
|
-54
|
||||||
|
96
|
||||||
|
71
|
||||||
|
99
|
||||||
|
81
|
||||||
|
30
|
||||||
|
-7
|
||||||
|
76
|
||||||
|
-22
|
||||||
|
43
|
||||||
|
62
|
||||||
|
-49
|
||||||
|
73
|
||||||
|
59
|
||||||
|
75
|
||||||
|
36
|
||||||
|
39
|
||||||
|
15
|
||||||
|
51
|
||||||
|
-51
|
||||||
|
63
|
||||||
|
69
|
||||||
|
1
|
||||||
|
1
|
||||||
|
-25
|
||||||
|
-18
|
||||||
|
88
|
||||||
|
86
|
||||||
|
93
|
||||||
|
33
|
||||||
|
71
|
||||||
|
-95
|
||||||
|
56
|
||||||
|
2
|
||||||
|
4
|
||||||
|
11
|
||||||
|
-55
|
||||||
|
28
|
||||||
|
60
|
||||||
|
-55
|
||||||
|
-69
|
||||||
|
-97
|
Loading…
x
Reference in New Issue
Block a user