Du befindest dich hier: FSI Informatik » Prüfungsfragen und Altklausuren » Prüfungen im Bachelor-Studium (1. - 5. Semester) » pfp » Lösungsversuch (Übersicht)
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige ÜberarbeitungVorherige ÜberarbeitungNächste Überarbeitung | Vorherige Überarbeitung | ||
pruefungen:bachelor:pfp:loesungws14 [13.07.2017 19:51] – Ergänzung Aufgabe2c ab21ajus | pruefungen:bachelor:pfp:loesungws14 [21.07.2018 19:41] (aktuell) – evren | ||
---|---|---|---|
Zeile 38: | Zeile 38: | ||
Begründung: | Begründung: | ||
value ist nicht volatile, durch Sichbarkeitsprobleme kann es hier zu einem Deadlock kommen, nämlich gerade dann wenn MyThread2 nichts von der Änderung in MyThread1 mitbekommt. | value ist nicht volatile, durch Sichbarkeitsprobleme kann es hier zu einem Deadlock kommen, nämlich gerade dann wenn MyThread2 nichts von der Änderung in MyThread1 mitbekommt. | ||
- | |||
- | EDIT: Sicher? Die Methode set() ist synchronized, | ||
==== Aufgabe 3 (Petri-Netze) ==== | ==== Aufgabe 3 (Petri-Netze) ==== | ||
Zeile 46: | Zeile 44: | ||
**b)** | **b)** | ||
- | Keine Zyklen, aus denen man nicht mehr heraus kommt! | + | Wenn irgendwann einmal wieder jede Transition (t1 - t4) schalten/ |
- | EDIT: finde obige Formulierung etwas ungenau/ | + | Beispiele für ein **nicht** lebendiges Petri-Netz:\\ |
+ | - Eine Belegung [x, y, z] in einem Erreichbarkeitsgraphen aus dem keine Pfeile gehen (Deadlock)\\ | ||
+ | - Zyklus in dem nicht alle möglichen Belegungen erreicht werden (Lifelock)\\ | ||
**c)** | **c)** | ||
Zeile 114: | Zeile 114: | ||
} | } | ||
</ | </ | ||
+ | \\ | ||
+ | (ich glaube im oberen Code ist ein barrier.await() zu viel) \\ | ||
+ | Alternativlösung: | ||
+ | 1: | ||
+ | <code java> | ||
+ | this.barrier = new CyclicBarrier(threads + 1); | ||
+ | </ | ||
+ | \\ | ||
+ | 2: | ||
+ | <code java> | ||
+ | for (int i = 0; i < thread; i++) { | ||
+ | int end = start + step; | ||
+ | if (end >= array.length) end = array.length - 1; | ||
+ | |||
+ | (new CountingThread(start, | ||
+ | |||
+ | start = end + 1; | ||
+ | if (i != array.length - 1 && start >= array.length) { | ||
+ | threads = i; | ||
+ | barrier = new CyclicBarrier(i + 1); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | 3: | ||
+ | <code java> | ||
+ | for (int i = 0; i < count.length; | ||
+ | </ | ||
+ | \\ | ||
+ | 4 (nur oberes Feld): | ||
+ | <code java> | ||
+ | barrier.await(); | ||
+ | </ | ||
+ | \\ | ||
+ | \\ | ||
==== Aufgabe 5 (Scala - Listenoperationen) ==== | ==== Aufgabe 5 (Scala - Listenoperationen) ==== | ||
**a)** | **a)** | ||
- | < | + | < |
def flatten : List[(Char, Char)] => List[Char] = { | def flatten : List[(Char, Char)] => List[Char] = { | ||
case Nil => List() | case Nil => List() | ||
case t :: ts => List(t._1, t._2) ::: flatten(ts) | case t :: ts => List(t._1, t._2) ::: flatten(ts) | ||
} | } | ||
+ | </ | ||
+ | |||
+ | Alternativlösung: | ||
+ | <code scala> | ||
+ | def flatten : List[(Char, Char)] => List[Char] = { | ||
+ | case Nil => Nil | ||
+ | case (a, b) :: tailList => a :: List(b) ::: flatten(tailList) | ||
+ | } | ||
</ | </ | ||
**b)** | **b)** | ||
- | < | + | < |
def countPar : List[Char] => List[(Char, Int)] = cs => { | def countPar : List[Char] => List[(Char, Int)] = cs => { | ||
for (c <- cs) yield (c, cs.par.filter(_ == c).size) | for (c <- cs) yield (c, cs.par.filter(_ == c).size) | ||
Zeile 132: | Zeile 175: | ||
**c)** | **c)** | ||
- | < | + | < |
def distinct : List[(Char, Int)] => List[(Char, Int)] = cs => { | def distinct : List[(Char, Int)] => List[(Char, Int)] = cs => { | ||
cs.foldLeft(List[(Char, | cs.foldLeft(List[(Char, | ||
Zeile 140: | Zeile 183: | ||
==== Aufgabe 6 (Scala - Lauflängenkodierung) ==== | ==== Aufgabe 6 (Scala - Lauflängenkodierung) ==== | ||
**a)** | **a)** | ||
- | < | + | < |
def decodeTuple: | def decodeTuple: | ||
case (c, 1) => Stream(c) | case (c, 1) => Stream(c) | ||
Zeile 149: | Zeile 192: | ||
**b)** | **b)** | ||
Geht für '' | Geht für '' | ||
- | < | + | < |
def decode: Stream[(Char, | def decode: Stream[(Char, | ||
case null => Stream() | case null => Stream() | ||
Zeile 155: | Zeile 198: | ||
} | } | ||
</ | </ | ||
- | Alternativlösung: | + | Alternativlösungen: |
- | < | + | < |
def decode: Stream[(Char, | def decode: Stream[(Char, | ||
case Stream.Empty => Stream.Empty | case Stream.Empty => Stream.Empty | ||
case ts => decodeTuple(ts.head) #::: decode(ts.tail) | case ts => decodeTuple(ts.head) #::: decode(ts.tail) | ||
+ | } | ||
+ | </ | ||
+ | <code scala> | ||
+ | def decode: Stream[(Char, | ||
+ | case Stream.Empty => Stream.Empty | ||
+ | case first #:: tailList => decodeTuple(first) #::: decode(tailList) | ||
} | } | ||
</ | </ |