Du befindest dich hier: FSI Informatik » Prüfungsfragen und Altklausuren » Prüfungen im Bachelor-Studium (1. - 5. Semester) » pfp » Forendiskussionen (Übersicht)
Dies ist eine alte Version des Dokuments!
Inhaltsverzeichnis
Forendiskussionen
Lösungsversuch
Aufgabe 1: Wissensfragen
a) falsch
b) nein
c) nein
d) richtig
e) 30s
f) def f: (Int, Int) ⇒ Int ⇒ Int ⇒ Int
g) falsch
Aufgabe 2: Petri-Netze
a) Verknüpfung von Service aktiv mit Transition t0. Zweiten Ausgang von t0 an Service aktiv setzen. Weitere Transition, die nur Stelle Service aktiv als Eingang hat.
b) Verknüpfung von Stelle Arbeitspakete jeweils mit Transitionen t1, t2 und t3. Stellenbeschränkung bei A, B, C auf 1 setzen. Verknüpfen von Transitionen t4, t5, t6 mit Stelle Arbeitsergebnisse
c)
- Token in Stelle Service aktiv
- Keine Token in Stelle Arbeitspakete
- Jeweils ein Token in Stellen A und B
- 2 Token in Stelle Arbeitsergebnisse
Endbild EDIT: ich glaube, in Stelle C soll kein Marke sein. EDIT: Bin ich auch der Meinung.
d) Nein (siehe Ablauf t3 → t1 → t1)
e) e) S = {0, 1, 1}T ; M = {t1: {-1, 1, 0}, t2: {-1, 0, 1}, t3: {2, -1, -1} }T
Aufgabe 3: Datei-Suche
a)
activeFolderSearchers = new AtomicInteger(0); Thread t = new FolderSearcher(rootDir); // incrementAndGet() muss vor dem Starten kommen! activeFolderSearchers.incrementAndGet(); t.start(); //t.join();
b)
if(file.isDirectory()) { Thread t = new FolderSearcher(file); activeFolderSearchers.incrementAndGet(); t.start(); } else if(file.isFile()) { pool.submit(new FileSearcher(file)); }
c)
int i = activeFolderSearchers.decrementAndGet(); if(i == 0){ pool.shutdown(); // Shall only be called once! }
Aufgabe 4: Scala - Teilersummen
a)
def construct: (Int => List[Int]) => (List[Int] => Int) => Int => Int = f => s => n => s(f(n))
b)
def fss: Int => Stream[(Int, Int)] = n => (n, fs(n)) #:: fss(n+1)
c)
def count: (Int, Int) => Int = (n0, m) => fss(n0).take(m).foldLeft(0){ (a, b) => if(b._1 > b._2) a+1 else a; }
Aufgabe 5: Schreibtischlauf
a)
- Ausgabe — Alternative Ausgaben
- Question to Deep Thought: — Keine Alternative
- Leerzeile — Keine Alternative
- Answer to the: — Keine Alternative
- Ultimate Question — Douglas
- of Life — Keine Alternative
- Adams — The Universe
- and Everything — Keine Alternative
b)
- Ultimate Question:
- Zeile 7: int counter = 0 ⇒ AtomicInteger counter = new AtomicInteger(0);
- Zeile 16 & 69: counter++ ⇒ counter.IncrementAndGet();
- Zeile 71: counter ⇒ counter.get();
- The Universe:
- Zeile 30 & 82: synchronized(this) ⇒ synchronized(Bar.class)
Aufgabe 6 (Scala - Ausgehende Kanten)
*a)
def outEdges: (List[V],G) => List[E] = (vs,g) => g.par.filter(x => vs.contains(x._1) && !vs.contains(x._2)).toList
*b)
def tree: (V,G) => G = (v,g) => { def helper: List[V] => G = vs =>{ val a = outEdges(vs,g) if(a==Nil)Nil else a.head::helper(a.head._2::vs) } helper(List(v)) }
was hat das hier verloren? ich vermute mal magicSquare aus Aud ? :D
Aufgabe 7 (Backtracking)
a)
static boolean isSolved(int[][] sq) { int n = sq.length; int checkSum = ((n * n * n) + n) / 2; int rowSum = 0, colSum = 0, diag1Sum = 0, diag2Sum = 0; for(int y= 0 ; y< n; y++){ diag1Sum += sq[y][y]; diag2Sum += sq[n-1-y][n-1-y]; for(int x=0; x < n ; x++){ rowSum += sq[y][x]; colSum += sq[x][y]; } if(rowSum != checkSum || colSum != checkSum) return false; rowSum=colSum=0; } if(diag1Sum != checkSum || diag2Sum != checkSum) return false; return true; }
b)
static boolean solve(int[][] sq, int pos, boolean[] used) { int n = sq.length; int col = pos % n; int row = (pos - col) / n; // Basisfall if(isSolved(sq)) return true; //Rekursion for(int i=0; i < n*n; i++){ if(!used[i]){ used[i]=true; int c=i+1; sq[col][row]=c; if(solve(sq,pos+1,used)) return true; sq[col][row]=0; used[i]=false; } } return false; }