180 likes | 369 Views
Grundlagen der Informatik. Prof. Wolfgang SLANY. Turing Maschinen. Alan Turing 1936 Speicherplatz: 2D, Anfangsecke, nach rechts und nach oben beliebig viel Platz, „Anfangsbeschriftung“ Symbole: „leerer Platz“, „0“, „1“, „2“, …
E N D
Grundlagen der Informatik Prof. Wolfgang SLANY Grundlagen der Informatik - Prof. Slany
Turing Maschinen • Alan Turing 1936 • Speicherplatz: • 2D, Anfangsecke, nach rechts und nach oben beliebig viel Platz, „Anfangsbeschriftung“ • Symbole: „leerer Platz“, „0“, „1“, „2“, … • Zustände: Anfangszustand „Schwarz“, weitere „Grün“, „Rot“, „halte an“, … • Menge von Übergangsregeln • Marvin-10 + Labyrinth Grundlagen der Informatik - Prof. Slany
Turing Maschinen • Normalerweise ist Speicher nicht 2D, sondern ein-dimensional = Original TM mit nur einem 1D Speicherband (1 tapeturingmachine), einfachstes Modell • Realistisches 1D Speichermodell • Zustand = „Akkumulator“, „Register“ • Schreibe/Lesekopf = Marvin-10 = Cursor = Pointer • Übergangsregeln: realistisches Modell für CPU (centralprocessingunit) und Maschinensprache • Programme: Assembler-Code Grundlagen der Informatik - Prof. Slany
Turing Maschinen • Simulationeiner 2D TM (zB Marvin-10) auf einer 1D TM: • Zeilen „hintereinander“ auf einem Band, durch spezielle Symbole getrennt • Zeilenwechsel = vorherige Zeile oder nächste Zeile; Platz: Verschieben eines Cursor-Symbols in ursprünglicher Zeile, parallel dazu in neuer Zeile: viel hin und her „Gerenne“ • Gut machbar? • Effektiv? • Effizient? Grundlagen der Informatik - Prof. Slany
Turing Maschinen • Zusätzlicher zeitlicher Aufwand: • 1 horizontaler Schritt = gleich, außer wenn neues Feld: ca. • 1 vertikaler Schritt, maximale Zeilenlänge n (zBn = 10): • Pro Zellenentfernung m (zBm = 4) zum Beginn circa 2 x m x n • Im schlechtesten Fall ist m = n, d.h. Aufwand = 2 x n2 • Zeitlicher Zusatzaufwand bei der Simulation: circa 2 x n2 • Zusätzlicher Speicherverbrauch: vernachlässigbar Grundlagen der Informatik - Prof. Slany
k-tape TM • Nicht nur ein Speicherband, sondern k • k „Roboter“, 1 „Schritt“ bewegt alle Roboter gleichzeitig in unabhängige Richtungen • Simulation auf 1D TM: zeitlicher und Speicher-aufwand ähnlich wie bei 2D, nur dass jetzt immer k-Bänder bearbeitet werden müssen • Suche nach dem gleichem Platz fällt wegen speziellen Cursor Symbol in jedem „Band“ weg • Bei jedem Schritt müssen aber alle „Bänder“ 2x durchlaufen werden, um die k Symbole zu lesen, und dann je nach Regel darauf zu reagieren (schreiben, …) • Detto 3D und andere Varianten (insertetc) Grundlagen der Informatik - Prof. Slany
TM vs heutiger Computer • Von Neumann Architektur 1946 • Maschinensprache: Register, READ, WRITE, ADD, SUB, JUMP-IF-ZERO, … • Darauf aufbauend höhere Programmiersprachen (C, C++, Java …) • Zusammenhang mit Turing Maschinen?!? Grundlagen der Informatik - Prof. Slany
TM vs heutiger Computer Random Access Machine (RAM) • Achtung: RAM = Random Access Memoryvs Random Access Machine • Ähnlich wie Maschinensprache: READ, WRITE, ADD, SUB, JUMP-IF-ZERO, … • Wenn ein Problem in Zeit f(n) auf einer beliebigen TM gelöst werden kann, dann gibt es ein RAM-Programm, das dieses Problem in O(f(n)) Schritten löst Grundlagen der Informatik - Prof. Slany
O() Notation • f1(n) ist in O(f2(n)), • oder auch f1(n) = O(f2(n)) (Achtung: „=“ ist nur eine Schreibkonvention!) f1 wächst asymptotisch (n unendlich) nicht schneller als k x f2 (für ein bestimmtes k) • Beispiel: 4n5+3n2-7 ist in O(n5) (oder anders geschrieben: 4n5+3n2-7 = O(n5)) • Konstanter Faktor k ist wegen jederzeit möglichem linearen speedup (8bit vs 64 bit CPU etc) unerheblich • Mehr: http://en.wikipedia.org/wiki/O_notation Grundlagen der Informatik - Prof. Slany
TM vs heutiger Computer • RAM Programm, das ein Problem in f(n) Schritten löst, kann auf einer 7-bändigen Turing Maschine in O(f(n)3) Schritten simuliert werden (Grund für 7 Bänder: Zwischenergebnisse, Pointer, und einfach „schlampig“ programmiert) • D.h. auf der ursprünglichen ein-Band Turing Maschine in O((f(n)3)2) = O(f(n)6) • Super!!!: Hardware verbessert sich so schnell (exponentiell!), dass polynomielle Unterschiede kaum ins Gewicht fallen • Hexi! http://www.einspiel.net/ramsey/ Grundlagen der Informatik - Prof. Slany
Moore‘slaw (x 2 kleiner = schneller, alle 18~24 Monate, theoretisch noch 600 Jahre möglich …) Grundl. d. Informatik - Prof. Slany
Exponentielles Wachstum • Posting / Java … • The Java is Faster than C++ and C++ Sucks Unbiased Benchmark Rechnen Grundl. d. Informatik - Prof. Slany
„Tipping point“ • RAM Programm: f(n) Schritte • Ein-Band Turing Maschine: O(f(n)6) Schritte • Nach 20 Jahren: Ein-Band Turing Maschine ist 16x so schnell wie heutiger Computer • Marvin-10: nur O(f(n)3) • Nach 100 Jahren: mehr als 1,7 x 1013 x so schnell wie heutiger Computer … Grundl. d. Informatik - Prof. Slany
Polynome vs exponentielles Wachstum Grundlagen der Informatik - Prof. Slany
Story: First Half of the Chessboard • Chinese/Indian/Arab advisor did a great deed for his emperor who wants to reward him: • One grain of rice on the first square of the chess board, double that number of grains of rice on the second square, and so on Grundl. d. Informatik - Prof. Slany
Tipping point: Rice on Chessboard • First half of the chessboard is 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 ... + for a total of exactly 232 − 1 grains of rice, or about one field of rice. Economically insignificant to the emperor, no problem. • Second half of the chessboard is 232 + 233 +... + 263, for a total of 264-1 grains of rice. • 8000 years at current world production rate. Grundl. d. Informatik - Prof. Slany
Wichtige Beispiele • 43503 (konstant) = O(1) • 27 log(n) (logarithmisch) = O(log n) • 10 log(2n) – 7 (logarithmisch) = O(log n) • 13n + 8 log(3n) (linear) = O(n) • 24 n log (n) – 7n = O(n log n) • 17n2 + 100 n log (1000n) (quadrat.) = O(n2) • 1000 n50+ n51 (polynomiell) = O(n51) • 2n+n5000 (exponentiell) = O(2n) Grundl. d. Informatik - Prof. Slany
O() Notation Prüfungsbeispiel Grundlagen der Informatik - Prof. Slany