Du befindest dich hier: FSI Informatik » Prüfungsfragen und Altklausuren » Prüfungen im Bachelor-Studium (1. - 5. Semester) » aud » Lösungsversuch
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Nächste Überarbeitung | Vorherige ÜberarbeitungNächste ÜberarbeitungBeide Seiten, nächste Überarbeitung | ||
pruefungen:bachelor:aud:loesungss17 [19.10.2017 17:42] – angelegt jonpost | pruefungen:bachelor:aud:loesungss17 [19.10.2017 18:24] – solution 3a,b added jonpost | ||
---|---|---|---|
Zeile 23: | Zeile 23: | ||
**j)** 1 und 3 | **j)** 1 und 3 | ||
+ | * zu 4) | ||
+ | *=> | ||
+ | |||
+ | |||
+ | ==== Aufgabe 2 Suchen und O-Kalkül ==== | ||
+ | |||
+ | **a)** | ||
+ | <code java> | ||
+ | static int[] searchNaive(int[] a, int z) { | ||
+ | int[] r = null; | ||
+ | for(int i = 0; i < a.length; i++) { | ||
+ | for(int j = i+1; j < a.length; j++) { | ||
+ | if(a[i] + a[j] == z) { | ||
+ | r = new int[] {i, j}; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return r; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | **b)** | ||
+ | <code java> | ||
+ | static int[] searchLinear(int[] a, int z) { | ||
+ | int i = 1, j = a.length - 1; | ||
+ | while(i < j) { | ||
+ | if(a[i] + a[j] == z) { | ||
+ | return new int[] {i, j}; | ||
+ | } else if(a[i] + a[j] < z) { | ||
+ | i++; | ||
+ | } else { | ||
+ | j--; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | **c)** | ||
+ | <code java> | ||
+ | static LinkedList< | ||
+ | LinkedList< | ||
+ | AVLTree at = new AVLTree(); | ||
+ | | ||
+ | for(int x : a) { | ||
+ | at.insert(x); | ||
+ | } | ||
+ | | ||
+ | for(int x : b) { | ||
+ | AVLNode r = at.root; | ||
+ | | ||
+ | while(r != null) { | ||
+ | if(x < r.data) { | ||
+ | r = r.left; | ||
+ | } else if(x > r.data) { | ||
+ | r = r.right; | ||
+ | } else { | ||
+ | ds.add(x); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | return ds; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====Aufgabe 3 Bäume ==== | ||
+ | **a)** | ||
+ | | ^ B1 ^ B2 ^ B3 ^ | ||
+ | ^ Preorder: | ∧∨ab∨cd | ∨∧ab¬∨cd | ∨¬a∧¬b∨¬cd | | ||
+ | ^ Inorder: | (a∨b)∧(c∨d)) | a∧b∨¬(c∨d) | ¬a∨¬b∧(¬c∨d) | | ||
+ | ^ Postorder: | ab∨cd∨∧ | ab∧cd∨¬∨ | a¬b¬c¬d∨∧∨ | | ||
+ | |||
+ | **b)** | ||
+ | <code java> | ||
+ | LinkedList< | ||
+ | LinkedList< | ||
+ | | ||
+ | r.add(o); | ||
+ | for(KTree c : cs) { | ||
+ | r.addAll(c.toPrefix()); | ||
+ | } | ||
+ | | ||
+ | return r; | ||
+ | } | ||
+ | </ |