Lecture 1

This commit is contained in:
Oliver Hofmann committed 2024-03-26 09:37:43 +01:00
1 parent a5e104b9fc
commit 61208603d1
6 files changed
+11176 -4

No files matched your search

+14
View File
@@ -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
+48 -4
View File
@@ -1,4 +1,5 @@
class AlgoDatValue:
"""A class representing a value with statistics."""
memory = 0
read = 0
@@ -12,7 +13,6 @@ class AlgoDatValue:
@staticmethod
def summary():
print("*** Summary ***")
print(f"Memory: {AlgoDatValue.memory}")
print(f"Read: {AlgoDatValue.read}")
print(f"Write: {AlgoDatValue.write}")
@@ -23,7 +23,6 @@ class AlgoDatValue:
print(f"Div: {AlgoDatValue.div_operation}")
print(f"Bit: {AlgoDatValue.bit_operation}")
def __init__(self, value):
AlgoDatValue.memory += 1
AlgoDatValue.write += 1
@@ -228,8 +227,14 @@ class AlgoDatValue:
def __round__(self, n=0):
return round(self.value, n)
def __setattr__(self, name, value):
if name == "value":
AlgoDatValue.write += 1
self.__dict__[name] = value
class AlgoDatArray:
"""A class representing an array of AlgoDatValue objects."""
def __init__(self, size):
self.size = size
@@ -263,10 +268,49 @@ class AlgoDatArray:
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:
l = list(map(int, file.read().split()))
a = AlgoDatArray(len(l))
for i in range(len(l)):
a.set(i, AlgoDatValue(l[i]))
return a
return a
+14
View File
@@ -0,0 +1,14 @@
-59
52
46
14
-50
58
-87
-77
34
15
50
47
51
48
+100
View 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
+10000
View File
File diff suppressed because it is too large. Load diff
+1000
View File
@@ -0,0 +1,1000 @@
-82
-26
-90
-72
-48
-18
-2
-7
-10
-32
-6
-40
-31
-20
-70
-64
-38
-76
-66
-76
-92
-22
-89
-6
-19
-50
-47
-8
-14
-94
-42
-75
-71
-22
-70
-99
-18
-98
-89
-39
-79
-40
-96
-58
-30
-40
-37
-48
-78
-41
-90
-24
-78
-48
-47
-4
-89
-44
-11
-29
-48
-23
-6
-31
-67
-95
-17
-86
-7
-76
-10
-42
-83
-81
-7
-90
-39
-85
-87
-8
-5
-87
-80
-47
-17
-18
-96
-68
-19
-74
-71
-79
-92
-13
-26
-67
-52
-76
-23
-97
-74
-83
-53
-88
-7
-28
-45
-40
-2
-64
-79
-97
-8
-30
-39
-58
-27
-8
-71
-95
-69
-48
-27
-74
-27
-94
-77
-21
-31
-53
-64
-21
-98
-50
-98
-69
-51
-10
-78
-1
-9
-39
-10
-49
-45
-17
-17
-46
-73
-3
-22
-30
-68
-83
-32
-34
-55
-62
-36
-2
-57
-92
-98
-32
-8
-10
-33
-16
-96
-93
-99
-54
-2
-4
-19
-31
-50
-81
-46
-39
-48
-38
-69
-8
-7
-30
-93
-10
-24
-64
-7
-2
-77
-24
-25
-71
-74
-43
-40
-71
-30
-18
-37
-15
-32
-96
-21
-92
-39
-42
-8
-19
-63
-72
-20
-56
-81
-20
-99
-63
-10
-44
-90
-48
-55
-45
-67
-74
-54
-88
-32
-7
-12
-89
-14
-45
-53
-63
-4
-44
-29
-54
-61
-84
-41
-14
-8
-35
-97
-81
-12
-86
-37
-28
-96
-17
-11
-11
-39
-80
-77
-96
-22
-91
-95
-2
-63
-91
-81
-79
-68
-92
-32
-98
-21
-61
-5
-7
-13
-27
-7
-99
-4
-89
-63
-77
-22
-86
-53
-47
-27
-48
-86
-38
-66
-16
-8
-30
-90
-99
-99
-10
-32
-14
-82
-40
-66
-75
-64
-56
-7
-90
-10
-28
-39
-8
-3
-71
-57
-44
-14
-26
-58
-66
-31
-48
-33
-52
-62
-69
-79
-49
-98
-30
-55
-93
-20
-15
-37
-52
-15
-8
-66
-54
-97
-46
-15
-97
-6
-49
-59
-45
-75
-87
-86
-70
-96
-36
-44
-90
-28
-14
-65
-71
-91
-94
-47
-10
-33
-84
-43
-93
-14
-74
-24
-54
-56
-72
-49
-48
-84
-4
-75
-20
-23
-14
-43
-50
-11
-43
-45
-92
-60
-95
-33
-87
-60
-46
-6
-58
-29
-35
-38
-82
-88
-21
-77
-35
-1
-19
-17
-65
-91
-27
-1
-27
-50
-54
-44
-76
-70
-37
-45
-16
-68
-64
-92
-17
-61
-92
-10
-42
-74
-20
-59
-50
-2
-88
-38
-86
-83
-13
-35
-94
-48
-92
-7
-69
-23
-94
-32
-96
-40
-75
-89
-93
-29
-33
-77
-25
-74
-17
-59
-98
-89
-58
-82
-91
-77
-73
-46
-55
-32
-47
-99
-95
-19
-7
-4
-42
-84
-77
-78
-62
-83
-6
-1
-34
-72
-53
-18
-25
-7
-39
-77
-82
-60
-89
-60
-18
-48
-61
-19
-71
-48
-89
-75
-70
-46
-89
-57
-45
-18
-83
-29
-32
-58
-17
-45
-17
-85
-54
-48
-28
-50
-46
-44
-4
-36
-66
-85
-89
-82
-98
-63
-50
-59
-57
-31
-43
-18
-28
-61
-36
-50
-46
-15
-98
-64
-50
-75
-81
-99
-33
-64
-45
-74
-47
-96
-2
-63
-96
-29
-60
-47
-33
-25
-38
-5
-5
-26
-75
-98
-59
-56
-49
-16
-30
-83
-86
-12
-46
-10
-29
-8
-82
-50
-39
-89
-92
-65
-80
-67
-56
-5
-2
-20
-77
-93
-9
-90
-10
-48
-52
-18
-19
-87
-32
-60
-50
-16
-81
-87
-55
-57
-16
-26
-75
-20
-22
-39
-43
-74
-95
-82
-19
-91
-65
-60
-53
-67
-2
-77
-57
-94
-7
-76
-23
-40
-73
-8
-47
-70
-23
-26
-84
-98
-39
-25
-14
-44
-13
-60
-88
-78
-78
-43
-69
-18
-87
-16
-57
-49
-25
-39
-25
-24
-87
-44
-20
-91
-47
-57
-11
-69
-44
-55
-11
-23
-51
-98
-94
-6
-29
-82
-9
-60
-23
-9
-43
-79
-72
-95
-6
-6
-89
-48
-74
-24
-96
-75
-75
-38
-28
-54
-45
-70
-62
-92
-23
-3
-29
-86
-60
-14
-46
-80
-89
-73
-18
-57
-28
-11
-81
-78
-95
-74
-17
-24
-20
-63
-58
-92
-19
-64
-35
-87
-1
-50
-9
-73
-42
-31
-91
-42
-77
-65
-92
-78
-94
-34
-27
-11
-6
-17
-14
-84
-47
-22
-72
-35
-39
-70
-43
-6
-27
-52
-63
-60
-50
-60
-21
-50
-57
-92
-73
-55
-74
-56
-5
-2
-84
-62
-26
-22
-57
-45
-12
-82
-79
-36
-66
-36
-32
-75
-54
-5
-74
-60
-10
-86
-95
-20
-93
-29
-43
-2
-49
-27
-24
-42
-30
-75
-71
-81
-76
-13
-9
-9
-31
-62
-37
-99
-96
-77
-31
-92
-40
-70
-24
-34
-13
-62
-55
-78
-44
-63
-10
-81
-90
-79
-81
-59
-66
-83
-47
-51
-68
-48
-28
-56
-47
-48
-67
-86
-42
-31
-60
-60
-78
-60
-63
-76
-84
-59
-81
-99
-69
-86
-7
-90
-95
-46
-69
-71
-74
-68
-43
-74
-93
-79
-67
-9
-22
-58
-60
-15
-14
-11
-48
-25
-6
-41
-94
-69
-27
-1
-37
-19
-27
-10
-76
-15
-55
-76
-13
-91
-30
-84
-49
-26
-80
-26
-73
-21
-15
-30
-15
-60
-38
-1
-84
-82
-79
-54
-89
-36
-94
-59
-8
-48
-74
-53
-59
-82
-75
-14
-24
-42
-17
-95
-83
-56
-79
-99
-28
-15
-54
-71
-73
-5
-15
-55
-38
-61
-21
-50
-66
-61
-89
-17
-90
-12
-56
-49
-47
-56
-43
-17
-36
-69
-77
-34
-6
-30
-94
-6
-39
-47
-41
-88
-1
-49
-98
-54
-9
-61
-77
-68
-38
-64
-31
-73
-4
-53
-46
-69
-85
-58
-49