Informatik II Übung 11 Gruppe 4

Ähnliche Dokumente
Informatik II - Übung 11

Informatik II - Übung 11

Informatik II (D-ITET) Übungsstunde 11,

Informatik II Übung 11 Gruppe 7

Informatik II Übung 11 Gruppe 3

Informatik II - Übung 10

Informatik II (D-ITET) Übungsstunde 10,

Informatik II Übung 11. Pascal Schärli

Informatik II Übung 9. Pascal Schärli

Informatik II Übung 09

Informatik II Übung 10. Pascal Schärli

Informatik II - Tutorium 12

Informatik II Übung 8 Gruppe 4

Informatik II Übung 09. Benjamin Hepp 3 May 2017

Informatik II - Übung 10

Informatik II - Übung 12

Informatik II - Übung 07

Informatik II. Woche 15, Giuseppe Accaputo

Informatik II Übung 10. Benjamin Hepp 10 May 2017

Informatik II Übung 5 Gruppe 4

Informatik II - Übung 07. Christian Beckel

Informatik II - Übung 08

Informatik II Übung 08

Informatik II - Tutorium 9

Informatik II Übung 7 Gruppe 7

Rekursive Funktionen

Informatik II Übung 7. Pascal Schärli

Kapitel 10. Komplexität von Algorithmen und Sortieralgorithmen

// Objekt-Methoden: public void insert(int x) { next = new List(x,next); } public void delete() { if (next!= null) next = next.next; } public String

Kapitel 9. Komplexität von Algorithmen und Sortieralgorithmen

Übung 4: Die generische Klasse AvlBaum in Java 1

Java. public D find(k k) { Listnode K, D n = findnode(k); if(n == null) return null; return n.data; Java

Algorithmen und Programmierung III

Kapitel 9. Komplexität von Algorithmen und Sortieralgorithmen

Übung zu Algorithmen und Datenstrukturen (für ET/IT)

Sortieralgorithmen OOPM, Ralf Lämmel

Informatik II Übung 2. Pascal Schärli

Datenstrukturen Teil 2. Bäume. Definition. Definition. Definition. Bäume sind verallgemeinerte Listen. Sie sind weiter spezielle Graphen

Komplexität von Algorithmen OOPM, Ralf Lämmel

Informatik II Übung 8. Pascal Schärli

Algorithmus Analyse. Johann Basnakowski

II.3.1 Rekursive Algorithmen - 1 -

Backtracking mit Heuristiken

Probeklausur zur Vorlesung

Vorlesung Datenstrukturen

Übungsstunde 11. Einführung in die Programmierung

Datenstrukturen sind neben Algorithmen weitere wichtige Bausteine in der Informatik

Rekursion. Rekursive Funktionen, Korrektheit, Terminierung, Rekursion vs. Iteration, Sortieren

Rekursion. Rekursive Funktionen, Korrektheit, Terminierung, Rekursion vs. Iteration, Sortieren

Datenstrukturen und Algorithmen (SS 2013) Prof. Dr. Leif Kobbelt Thomas Ströder, Fabian Emmes, Sven Middelberg, Michael Kremer

Algorithmen und Datenstrukturen

Informatik II, SS 2014

Komplexität eines Algorithmus, Grössenordnung, Landau-Symbole, Beispiel einer Komplexitätsberechnung (Mergesort) 7. KOMPLEXITÄT

Informatik II Übung 2

Informatik II, SS 2018

Informatik II, SS 2016

Informatik II - Tutorium 4

Wiederholungsblatt Einführung in die Programmierung Lösungen

Informatik II - Übung 08

Komplexität von Algorithmen

Einführung in die Programmierung WS 2009/10. Übungsblatt 7: Imperative Programmierung, Parameterübergabe

Aufgabenblatt 4. Aufgabe 3. Aufgabe 1. Aufgabe 2. Prof. Dr. Th. Letschert Algorithmen und Datenstrukturen

Anwendungsbeispiel MinHeap

Datenstrukturen und Algorithmen (SS 2013)

Algorithmen und Programmierung III

Vorkurs Informatik WiSe 17/18

Otto-von-Guericke-Universität Magdeburg Fakultät für Informatik Institut für Simulation und Graphik Prof. Dr. Holger Theisel

Software Entwicklung 1

Programm heute. Algorithmen und Datenstrukturen (für ET/IT) Übersicht: Graphen. Definition: Ungerichteter Graph. Definition: Ungerichteter Graph

JAVA - Suchen - Sortieren

Ziele. Kapitel 10: Komplexität von Algorithmen und Sortierverfahren. Beispiel: Lineare Suche eines Elements in einem Array (1)

Laufzeit & Komplexität

Übung Algorithmen und Datenstrukturen

Informatik II Übung 3. Pascal Schärli

Übung Algorithmen und Datenstrukturen

Mergesort. Inhaltsverzeichnis. Veranschaulichung der Funktionsweise. aus Wikipedia, der freien Enzyklopädie

Tutoraufgabe 1 (Implementierung eines ADTs):

Informatik II Übung 9

Informatik II Übung 06. Benjamin Hepp 5 April 2017

Übung Algorithmen I

Informatik II Übung 1 (slides teils von Christian Beckel) Gruppe 4. Lukas Burkhalter

Übungen zum Vortrag Backtracking mit Heuristiken

ÜBUNGSKLAUSUR Studienhalbjahr: 2. Semester. Datum: 20. Juli 2016 Bearbeitungszeit: 90 Minuten. Modul: T2INF Dozent: Stephan Schulz

Suchen und Sortieren OOPM, Ralf Lämmel

Informatik II, SS 2016

Informatik II (D-ITET)

UE Algorithmen und Datenstrukturen 1 UE Praktische Informatik 1. Übung 5. Asymptotische Laufzeitkomplexität Definition Regeln Beispiele

Programmieren in Java

Prüfung Algorithmen und Datenstrukturen I

Informatik II, SS 2014

Informatik II: Algorithmen & Datenstrukturen. Blättern Sie nicht um bevor Sie dazu aufgefordert werden!

Name: Seite 2. Beantworten Sie die Fragen in den Aufgaben 1 und 2 mit einer kurzen, prägnanten Antwort.

Einstieg in die Informatik mit Java

Listen. Prof. Dr. Christian Böhm. in Zusammenarbeit mit Gefei Zhang. WS 07/08

Schnittstellen, Stack und Queue

Technische Universität Braunschweig Institut für Programmierung und Reaktive Systeme

Abgabe: (vor der Vorlesung) Aufgabe 3.1 (P) Master-Theorem

Transkript:

Informatik II Übung 11 Gruppe 4 (Folien teils von Christian B. und Christelle G.) Lukas Burkhalter lubu@inf.ethz.ch Informatik II Übung 11 Lukas Burkhalter 16. Mai 2018 1

Alpha-Beta klarer 4 oder 2, beides ok 2

C B A Nachbesprechung letzte Übung 10 3

Merge-Sort Papier 21 15 9 63 45 44 8 88 98 67 45 6 62 21 15 63 9 45 44 88 8 98 67 45 6 62 63 21 15 9 88 45 44 8 98 67 45 6 62 88 63 45 44 21 15 9 8 98 67 62 45 6 98 88 67 63 62 45 45 44 21 15 9 8 6 4

Mergesort Pseudocode (sort) ArrayList sort (ArrayList unsorted, int begin, int end ) if ( end - begin == 0 ) return new ArrayList ( 0 ) if ( end - begin == 1 ) ArrayList result = new ArrayList ( 1 ) result.add ( unsorted[begin] ) return result // divide.. ArrayList lhs = sort ( unsorted, begin, (begin+end) / 2 ) ArrayList rhs = sort ( unsorted, (begin+end) / 2, end ) //..et impera return merge ( lhs, rhs ) 5

Mergesort Pseudocode (merge) ArrayList merge (ArrayList lhs, ArrayList rhs ) int left = 0, right = 0 ArrayList result = new ArrayList ( lhs.size + rhs.size ) loop if ( left == lhs.size ) result.addall ( rhs.sublist ( right, rhs.size ) ) break if ( right == rhs.size ) result.addall ( lhs.sublist ( left, lhs.size ) ) break result.add ( lhs[left]>rhs[right]? lhs[left++] : rhs[right++] ) return result 6

Mergesort Laufzeit 7

Türme von Hanoi Nicht benutzt wird: 3 2 1 Zusammenfassung: Anzahl der Scheiben (n): 4 Anzahl der Schritte (2 n-1 ): 15 Nicht benutzt werden: 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 8

Reversi Alpha-Beta Algorithmus BestMove max (int maxdepth, long timeout, GameBoard gb, int depth, int alpha, int beta) throws Timeout if (System.currentTimeMillis() > timeout) throw new Timeout(); if (depth==maxdepth) return new BestMove(eval(gb),null,true); ArrayList<Coordinates> availablemoves = new ArrayList<Coordinates>(gb.getSize()* gb.getsize()); for (int x = 1; x <= gb.getsize(); x++) for (int y = 1; y <= gb.getsize(); y++) { Coordinates coord = new Coordinates(x, y); if (gb.checkmove(mycolor, coord)) availablemoves.add(coord); } //Check available moves if (availablemoves.isempty()) if (gb.ismoveavailable(othercolor)) { BestMove result = min(maxdepth, timeout, gb, depth+1, alpha, beta); return new BestMove(result.value, null, false); } else return new BestMove(finalResult(gb), null, false); [...] //Falls keine available moves // Bewertungs funktion 9

BestMove max (int maxdepth, long timeout, GameBoard gb, int depth, int alpha, int beta) throws Timeout [...] boolean cut = false; Coordinates bestcoord = null; for (Coordinates coord : availablemoves) { GameBoard hypothetical = gb.clone(); hypothetical.checkmove(mycolor, coord); hypothetical.makemove(mycolor, coord); BestMove result = min(maxdepth, timeout, hypothetical, depth+1, alpha, beta); } if (result.value > alpha) { alpha = result.value; bestcoord = coord; } if (alpha >= beta) { return new BestMove(alpha, null, false); } cut = cut result.cut; // Passe alpha an falls nötig return new BestMove(alpha, bestcoord, cut); //Besuche Kind-Knoten //Rufe min() auf um den Kind-Wert zu erhalten // CUT wenn möglich 10

1. Sortieren mit Suchbäumen 2. Komplexitätsanalyse und O-Notation 3. Komplexität 4. Springer auf dem Schachbrett Vorbesprechung Übung 11 11

Sortieren von Suchbäumen [8, 10, 13, 4, 7, 6, 1, 3,14] Laufzeit? [1, 3, 4, 6, 7, 8, 10, 13, 14] Pre-order traversierung 12

Complexity Revisited O - Notation In der O-Notation halten wir aber nur den am schnellsten wachsende Term fest. Konstanten werden ignoriert! Beschreibt eine Menge von Funktionen 13

Komplexität von Algorithmen Was ist die Komplexität von func in Abhängigkeit von n, wenn wir davon Ausgehen, dass die Grundoperationen (+ - / *) je 1 Rechenschritt benötigen? n-mal private static int func(int n) { int out = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < i; j++) { out++; } } return out; } (0 + 1 + 2 + + n-1) = n*(n-1)/2 mal ausgeführt i++ j++ out++ Total: n + n*(n-1)/2 + n*(n-1)/2) 14

O-Notation abstrahiert private static int func(int n) { int out = 0; for(int i = 0; i < 10*(n*n); i++) { for(int j = 0; j < i; j++) { out++; } } return out; } 15

Example Java 16

Ü11.A2 Komplexität O-Notation // Fragment 1 for (int i=0; i<n; i++) a++; // Fragment 2 for (int i=0; i<2n; i++) a++; for (int j=0; j<n; j++) a++; // Fragment 4 for (int i=0; i<n; i++) for (int j=0; j<i; j++) a++; // Fragment 5 while(n >=1 ) n = n/2; // Fragment 3 for (int i=0; i<n; i++) for (int j=0; j<n; j++) a++; // Fragment 6 for (int i=0; i<n; i++) for (int j=0; j<n*n; j++) for (int k=0; k<j; k++) a++; 17

Ü11.A2 Komplexität Zeit pro Operation Max Grösse der Eingabe Totale Laufzeit 18

Ü11.A2 Komplexität (Beispiel) 19

Ü11.A4: Schachbrett Springer 20

Ü11.A4: Schachbrett Springer a) Klasse Position p = new Position(0,0); Position next = p.add(new Position(offX, offy)); Implementiert compareto, equals, etc. Methode getreachableset ArrayList<Position> getreachableset(position p, int n) p: Startposition n: Anzahl Hops returns: Knoten in der Menge 21

Ü11.A4: Schachbrett Springer b) Finde einen Weg, der...... alle Felder besucht... Jedes Feld nur 1x besucht Frühzeitiger Abbruch Falls erreichbare Felder alle besucht Backtracking: löschen der letzten Züge bis Abbruchbedingung nicht mehr erfüllt 22

Tipps Collections in Java 23

viel Spass! 24