Du befindest dich hier: FSI Informatik » Prüfungsfragen und Altklausuren » Prüfungen im Bachelor-Studium (1. - 5. Semester) » pfp » Forendiskussionen
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige ÜberarbeitungVorherige ÜberarbeitungNächste Überarbeitung | Vorherige ÜberarbeitungNächste ÜberarbeitungBeide Seiten, nächste Überarbeitung | ||
pruefungen:bachelor:pfp:loesungws13 [16.07.2014 09:23] – lemur | pruefungen:bachelor:pfp:loesungws13 [12.07.2017 18:37] – ab21ajus | ||
---|---|---|---|
Zeile 4: | Zeile 4: | ||
===== Lösungsversuch ===== | ===== Lösungsversuch ===== | ||
- | |||
- | Fehlende Aufgaben: 4, 6 | ||
==== Aufgabe 1: Wissensfragen ==== | ==== Aufgabe 1: Wissensfragen ==== | ||
Zeile 42: | Zeile 40: | ||
Endbild | Endbild | ||
+ | EDIT: ich glaube, in Stelle C soll kein Marke sein. | ||
+ | EDIT: Bin ich auch der Meinung. | ||
**d)** Nein | **d)** Nein | ||
Zeile 52: | Zeile 52: | ||
activeFolderSearchers = new AtomicInteger(0); | activeFolderSearchers = new AtomicInteger(0); | ||
Thread t = new FolderSearcher(rootDir); | Thread t = new FolderSearcher(rootDir); | ||
- | t.start(); | + | |
+ | // incrementAndGet() muss vor dem Starten kommen! | ||
activeFolderSearchers.incrementAndGet(); | activeFolderSearchers.incrementAndGet(); | ||
+ | t.start(); | ||
+ | |||
//t.join(); | //t.join(); | ||
</ | </ | ||
Zeile 59: | Zeile 62: | ||
**b)** | **b)** | ||
<code java> | <code java> | ||
- | if(file.isDirectory){ | + | if(file.isDirectory()) { |
- | Thread t = new FolderSearcher(file); | + | Thread t = new FolderSearcher(file); |
- | activeFolderSearchers.incrementAndGet(); | + | activeFolderSearchers.incrementAndGet(); |
- | t.start(); | + | t.start(); |
- | } else { if(file.isFile()){ | + | } else if(file.isFile()) { |
- | pool.submit(new FileSearcher(file)); | + | pool.submit(new FileSearcher(file)); |
- | } | + | |
} | } | ||
</ | </ | ||
Zeile 71: | Zeile 73: | ||
**c)** | **c)** | ||
<code java> | <code java> | ||
- | activeFolderSearchers.decrementAndGet(); | + | int i = activeFolderSearchers.decrementAndGet(); |
- | if(activeFolderSearchers.get() | + | if(i == 0){ |
- | pool.shutdown(); | + | pool.shutdown(); |
} | } | ||
</ | </ | ||
+ | |||
+ | ==== 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, | ||
+ | </ | ||
+ | **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 ==== | ==== Aufgabe 5: Schreibtischlauf ==== | ||
Zeile 95: | Zeile 116: | ||
* The Universe: | * The Universe: | ||
- | * Zeile 30 & 82: synchronized(this) | + | * Zeile 30 & 82: synchronized(this) |
- | ==== Aufgabe 6: Scala / Graphen faerben | + | ====Aufgabe 6 (Scala - Ausgehende Kanten) |
- | **a)** | + | |
- | | + | *a) |
- | def helper : (List[Color], Int) => Color = { | + | def outEdges: (List[V],G) => List[E] |
- | | + | g.par.filter(x => vs.contains(x._1) && !vs.contains(x._2)).toList |
- | | + | *b) |
- | } | + | def tree: (V,G) => G = (v,g) => { |
- | helper(c,0) | + | def helper: List[V] => G = vs =>{ |
- | } | + | val a = outEdges(vs,g) |
+ | if(a==Nil)Nil else a.head::helper(a.head._2:: | ||
+ | } | ||
+ | helper(List(v)) | ||
+ | } | ||
+ | ==== Aufgabe 7 (Backtracking) ==== | ||
+ | [[pruefungen: | ||
- | oder eleganter: | + | **a)** |
+ | <code java> | ||
+ | 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; | ||
- | def getFreeColor: | + | rowSum=colSum=0; |
+ | } | ||
+ | |||
+ | if(diag1Sum | ||
+ | return false; | ||
+ | |||
+ | return true; | ||
+ | } | ||
+ | |||
+ | </ | ||
**b)** | **b)** | ||
- | def colorGraph: List[Node] => List[Coloring] => List[Coloring] = { | ||
- | case Nil => cols => cols | ||
- | case n::nod => cols => colorGraph(nod)(nextFreeColor(cols)(n):: | ||
- | } | ||
+ | <code java> | ||
+ | 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; | ||
+ | |||
+ | // | ||
+ | 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, | ||
+ | return true; | ||
+ | |||
+ | sq[col][row]=0; | ||
+ | used[i]=false; | ||
+ | } | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | </ |