Browse Source

Lecture 1

master
Oliver Hofmann 8 months ago
parent
commit
61208603d1
6 changed files with 11176 additions and 4 deletions
  1. 14
    0
      README.md
  2. 48
    4
      SoSe24/algodat/foundation.py
  3. 14
    0
      seq0.txt
  4. 100
    0
      seq1.txt
  5. 10000
    0
      seq2.txt
  6. 1000
    0
      seq3.txt

+ 14
- 0
README.md 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
SoSe24/algodat/foundation.py 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
- 0
seq0.txt View File

@@ -0,0 +1,14 @@
-59
52
46
14
-50
58
-87
-77
34
15
50
47
51
48

+ 100
- 0
seq1.txt 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
- 0
seq2.txt
File diff suppressed because it is too large
View File


+ 1000
- 0
seq3.txt
File diff suppressed because it is too large
View File


Loading…
Cancel
Save