Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann...

45
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg Persistenz

Transcript of Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann...

Page 1: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II, SS 2008Algorithmen und Datenstrukturen

Vorlesung 24Prof. Dr. Thomas Ottmann

Algorithmen & Datenstrukturen, Institut für InformatikFakultät für Angewandte WissenschaftenAlbert-Ludwigs-Universität Freiburg

Persistenz

Page 2: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 2

Motivation

Eine Datenstruktur heißt ephemer, wenn zu jedem Zeitpunkt nur eine jeweils aktuelle Struktur existiert und jede Änderung der Struktur die alte Version zerstört.

Eine Struktur zur Speicherung einer Menge von Schlüsseln heißt vergesslich, wenn aus der aktuellen Gestalt der Struktur nicht auf die Erzeugungshistorie geschlossen werden kann.

Eine Struktur heißt persistent, wenn neben der aktuellen auch frühere Versionen existieren.

Partiell persistent: Modifikationen nur bei aktueller, Zugriff (Suche) auch bei früheren Versionen möglich.

Voll persistent: Zugriff und Modifikation für alle VersionenKonfluent persistent: Mehrere frühere Versionen können zu neuer

aktueller Version verknüpft werden.

Page 3: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 3

Beispiel einer vergesslichen Struktur: Arrays

Array:

2 4 8 15 17 43 47 ……

Eindeutige Struktur, daher vergesslich!

Suchen: In Zeit O( log n) möglich, binäres Suchen

Update (Einfügen, Entfernen): (n)

Aber Vorsicht:Speicherbelegung könnte dennoch von Erzeugungshistorie abhängen!

Page 4: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 4

Beispiel: Natürliche Suchbäume

Nur teilweise vergesslich!

Einfügereihenfolge teilweise rekonstruierbar.

Entfernte Schlüssel nicht sichtbar.

Suchen, Einfügen. Entfernen von Schlüsseln: (n) Zeit

1, 3, 5, 7 5, 1, 3, 7

13

57 3

1

5

7

Page 5: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 5

Strategien, um Strukturen vergesslich zu machen

Mache die Struktur eindeutig:

Mengeneindeutigkeit: Für jede Menge von n Schlüsseln gibt es genau eine Struktur, die sie speichert.

Die Speicherung ist ordnungseindeutig, d.h. die Knoten der Struktur sind angeordnet und die Schlüssel sind der Größe nach in den Knoten mit aufsteigenden Nummern gespeichert.

Randomisiere die Struktur:

Sichere, dass der Erwartungswert für das Auftreten einer Struktur, die eine Menge M von Schlüsseln speichert, unabhängig davon ist, wie M entstanden ist.

Beobachtung: Die Zuweisung von Speicheradressen zu Zeigern muss randomisiert erfolgen!

Page 6: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 6

Mengen- und ordnungseindeutige Strukturen

Untere Schranken?

Annahmen: Wörterbuch der Größe n wird repräsentiert durch Graphen mit n Knoten, Knotengrad endlich (fest), feste Ordnung der Knoten, i-ter Knoten speichert i-ten Schlüssel.

Operationen zur Veränderung von Graphen:

Schaffen | Entfernen von Knoten

Pointer change

Austausch von Schlüsseln

Satz: Für jede mengen- und ordnungs-eindeutige Repräsentation von Wörterbüchern gilt, daß wenigstens eine der drei Operationen Suchen, Einfügen und Entfernen Zeit (n1/3) kostet.

Page 7: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 7

Sprung-Listen

(Halbdynamische) 2-Ebenen Sprung-Listen

2-Ebenen-Sprung-Liste der Größe n

niini 22 )1(

Suchen: O(i) = O(n) ZeitEinfügen und Entfernen:

ebenfalls in Zeit O(n)

22 4113

tail

0 i 2i n

(n-1)/i · i

2 3 5 7 8 10 11 12 14 17 19

Page 8: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 8

c-Ebenen Sprung-Listen

Satz: Für jedes c ≥ 3 sind c-Ebenen Sprung-Listen eine größen- und ordnungseindeutige Repräsentation von Wörterbüchern mit folgenden Eigenschaften:

Platzbedarf O(c·n)Suchzeit O(c·n1/c)

Updatezeit , falls n gerade

, falls n ungerade

)( nO)( 2/)1( ccnO

Page 9: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 9

Strategien, um Strukturen (partiell) persistent zu machen

Kopiere gesamte Struktur vor jeder Update-Operation, liefert volle Persistenz zum Preis von (n) Zeit pro Update und Platz (m n) für m Updates auf Strukturen der Größe n. (Struktur-Kopier-Methode)

Tue nichts sondern speichere ein log-File der Updates! Um auf Version i zuzugreifen, führe zunächst die i ersten Updates auf der Anfangsstruktur aus, um Version i zu erzeugen. (i) Zeit per Zugriff, O(m) Platz für m Operationen.

Hybrid-Ansatz: Speichere die gesamte Folge der Updates und zusätzlich jede k-te Version für ein geeignetes k. Folge: Zeit oder Platzbedarf nimmt mindestens um Faktor sqr(m) zu!

Gibt es bessere Methoden? …. Für Suchbäume ….

Page 10: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 10

Persistente Suchbäume

Methoden, um Suchbäume partiell persistet zu machen:

Fat-Node-Methode

Path-Copying-Methode

Node-Copying-Methode (DSST)

Page 11: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 11

Fat-Node-Methode

Speichere alle an einem Knoten vorgenommenen Änderungen in dem Knoten selbst.

Knoten speichern also die gesamte Versions-Historie und können daher beliebig „fat“ werden.

Versionsstempel in Knoten dienen dazu, die jeweils richtige Version auszuwählen.

Betrachte Update Operation i:

Ephemere Strutktur Persistente StrukturSchaffen eines neuen Knotens Schaffe neuen Knoten mit

Versionsstempel i und allen Originalwerten

Ändern eines Wertes Speichere neuen Wert mit Versionstempel

Page 12: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 12

Update Operation – Beispiel

(Versionen 1 bis 9) Einfüge: 5, 20, 8, 15, 6, 2, 1, 28, 12

5

20

8

156

2

28

12

1

(Versionen 10 bis 12) Entferne: 20, 5, 1

Page 13: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 13

Access Operation – Fat Node Method

Zugriff auf eine Version i m in der persistenten Structur:

Bestimme die Wurzel von Version i.

Durchlaufe die Knoten der Struktur, indem nur Versions Werte mit maximalem Versions Stempel i genutzt werden.

Beispiel: Gegeben folgtende persistente Structure, Zugriff auf Version v11

5

20

8

156

2

28

12

1

v1-v10

v6

v7

v2

v3

v4v5

v8

v9

v10

v10v10

v10

v11

v12

v11-v12

Page 14: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 14

Analysis – Fat Node Method

Annahme: Die Versions Stempel in einem Fat Node sind angeordnet und werden in einem balancierten Baum gespeichert

Maximale Zahl von Pointern in einem Fat-Node: m

Update Operation

Platzbedarf per Update:

Zeitbedarf per Update:

Zugriffs Operation

Zeitbedarf per Zugriff: (multiplikativer slow-down)

Page 15: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 15

Path-Copying Methode – Partielle Persistenz

Erzeugt eine Menge von Suchbäumen, je einen per Update, die sämtlich verschiedene Wurzeln, aber gemeinsame Teilbäume haben.

Man kopiert nur die Knoten, die in der aktuellen Version verändert werden, und alle Knoten, die auf solche Knoten verweisen.

Folgerung für Bäume: Kopieren eines Knotens in der aktuellen Version erfordert auch das Kopieren des gesamten Pfades von der Wurzel zu diesem Knoten. (Daher der Name der Methode!)

Page 16: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 16

Update Operation – Path-Copying

Betrachte Update Operation i.

Bestimme den Knoten in der aktuellen Version, der von der Update Operation betroffen ist

Kopiere diesen Knoten und den Pfad von der Wurzel zu diesem Knoten.

Page 17: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 17

Path-Copying (1)

Pfad-Kopier-Methode

5

1 7

3

0

Version 0:

Page 18: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 18

Path-Copying (2)

Pfad-Kopier-Methode

5 5

1 1 7

3 3

2

0 1

Version 1:Einfüge (2)

Page 19: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 19

Path-Copying (3)

Pfad-Kopier-Methode

5 5 5

1 1 1 7

3 3 3

2 4

0 1 2

Version 1:Einfüge (2)Version 2:Einfüge (4)

Page 20: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 20

Path-Copying (4)

Pfad-Kopier-Methode

Umstrukturierungs-Kosten O(log n) pro Update Operation

5 5 5

1 1 1 7

3 3 3

2 4

0 1 2

Version 1:Einfüge (2)Version 2:Einfüge (4)

Page 21: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 21

Update Operation – Beispiel (Einfügen)

(Versionen 1 bis 9) Einfügen: 5, 20, 8, 15, 6, 2, 1, 28, 12

5

20

8

156

2

1

… v7

Page 22: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 22

Update Operation – Example (Insert)

(Versionen 1 bis 9) Einfügen: 5, 20, 8, 15, 6, 2, 1, 28, 12

5

20

8

156

2

281

… v7

5

20

v8

Page 23: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 23

Update Operation – Beispiel (Einfügen)

(Versionen 1 bis 9) Einfügen: 5, 20, 8, 15, 6, 2, 1, 28, 12

5

20

8

156

2

28

12

1

… v7

5

20

v8

5

20

v9

8

15

Page 24: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 24

Update Operation –Beispiel (Entfernen)

(Versionen 10 bis 12) Entferne: 1, 20, 5

5

20

8

156

2

1

… v9

12

28

Page 25: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 25

Update Operation –Beispiel (Entfernen)

(Versionen 10 bis 12) Entferne: 1, 20, 5

5

20

8

156

2

1

… v9

12

28

5

2

v10

Page 26: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 26

Update Operation –Beispiel (Entfernen)

(Versionen 10 bis 12) Entferne: 1, 20, 5

5

20

8

156

2

1

… v9

12

28

5

2

v10

5

v11

15

8

Page 27: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 27

Update Operation –Beispiel (Entfernen)

(Versionen 10 bis 12) Entferne: 1, 20, 5

5

20

8

156

2

1

… v9

12

28

5

2

v10

5

v11

15

8

2

v12

Page 28: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 28

Zugriffs Operation – Path-Copying

Annahme: Die Wurzeln der verschiedenen Versionen sind angeordnet und werden in einer eigenen Zugriffsstruktur verwaltet, die den Zugriff auf jede der m Versionen erlaubt.

Zugriff auf Version vi:

Bestimme die Wurzel der Version vi und gehe von dort aus weiter.

Bemerkung: Die Path-Copying-Methode kann auch ausgedehnt werden auf Balanzierungsoperationen (Rotationen, Doppelrotationen).

Folgerung: Jede Operation (Einfügen, Entfernen inklusive Rebalanzieren) erfordert das Kopieren eines Pfades von der Wurzel zu einem Blatt, also von O(log n) Knoten für einen (bal.) Baum mit n Knoten.

Page 29: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 29

Node-Copying Methode – Partielle Persistenz

Verbesserung der Fat-Node-Methode: Jeder Knoten kann nur noch eine universell begrenzte Zahl von Versionsstempeln und versionierten Daten (Pointern) in eineM Modifikationsfeld enthalten.(Willkürliche Festlegung: Nur 1 Zeiger mit Zeitstempel)

Ist das Modifikationsfeld voll, wir der Knoten kopiert (mit leerem Modifikationsfeld)

Der Kopierprozess erfolgt “von unten”, nicht “von oben” wie bei der Path-Copying-Methode.

klp rp

vt: ptrOriginal left pointer to left child with version before vt

Original right pointer to right child with version before vt

Version stamp modification box

Page 30: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 30

Node-Copying (1)

Erweitere jeden Knoten um Modifikationsfeld mit Zeitstempel

? alle Versionenvor Zeit t

alle Versionenab Zeit t

Modifikationsfelder:sind anfangs leerwerden v.u.n.o. gefüllt

k

t: rp

lp rp

Page 31: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 31

Node-Copying (2)

5

1

3

7

Version 0

Page 32: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 32

Node-Copying (3)

5

1

3

2

7

1 lp

Version 0:

Page 33: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 33

Node-Copying (4)

5

1

3

2

3

4

7

1 lp

Version 1:Einfüge (2)Version 2:Einfüge (4)

Page 34: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 34

Node-Copying (5)

Die amortisierten Kosten (Zeit und Platz) pro Update Operation sind O(1)

5

1

3

2

3

4

72 rp

1 lp

Version 1:Einfüge (2)Version 2:Einfüge (4)

Page 35: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 35

Update Operation – Beispiel (Einfügen)

v0

5

20

8

(Versionen 1 to 6) Einfügen: 15, 6, 2, 1, 28, 12

Page 36: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 36

v0

5

20

v2:lp

8

v1:rp

(Versionen 1 bis 6) Einfügen: 15, 6, 2, 1, 28, 12

15

8

6

Update Operation – Beispiel (Einfügen)

Page 37: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 37

v0-v4

5

v3:lp

20

v2:lp

8

v1:rp

(Versionen 1 bis 6) Einfügen: 15, 6, 2, 1, 28, 12

15

v6:lp

8

6

2

v4:lp

1 28

20

5

v5-v6

12

Update Operation – Beispiel (Einfügen)

Page 38: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 38

Update Operation –Beispiel (Entfernen)

v0-v4

5

v3:lp

20

v2:lp

8

v1:rp

(Versionen 7 und 8) Entfernen: 1, 20

15

v6:lp

8

6

2

v4:lp

1 28

20

5

v5-v6

12

Page 39: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 39

Analyse – Node-Copying Method

Man kann zeigen, dass die amortisierten Kopier Kosten pro Update Operation konstant sind!

Man erhält also eine Struktur, die im Durchschnitt (über eine Folge von Update Operationen) nur um eine konstante Größe pro Update wächst!

Page 40: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 40

Anwendung: Planar Point Location

Page 41: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 41

Dobkin-Lipton Konstruktion

•Teile die Ebene in vertikale Streifen, die vertikal geordnet sind.

Page 42: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 42

Dobkin-Lipton Konstruktion

•Bestimme die Region, in die ein Punkt fällt, mit Hilfe von zwei binären Such-Operationen: •Anfrage Zeit: O(log n). Platz Bedarf O(n2).

Page 43: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 43

Worst-Case Beispiel

• Θ(n) Segmente in jedem Streifen, und Θ(n) Streifen.

Page 44: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 44

Cole’s Beobachtung

A B

•Mengen von Liniensegmenten in zwei benachbarten Streifen sind ähnlich!•Speichere die Streifen in einer “persistenten” Struktur.

Page 45: Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Informatik II: Algorithmen und Datenstrukturen, SS 2008Prof. Dr. Thomas Ottmann 45

Verringerung des Platzbedarfs

Baue einen (balanzierten) Suchbaum für den ersten Streifen; das ist Version 0. Platzbedarf dieser Struktur: O(n)

Erzeuge die jeweils nächste Version durch Löschen aller Segmente, die dort enden und Einfügen aller Segmente, die dort beginnen!

Insgesamt höchstens O(n) Einfüge- und Entferne-Operationen!

Also: Platzbedarf der gesamten, persistenten Struktur ist höchstens O(n), falls Node-Copying-Methode benutzt wird.

Das Point Location Problem kann gelöst werden mit Hilfe einer Struktur, die in Zeit O(n log n) aufgebaut werden kann, die Platzbedarf O(n) hat und eine Point-Location Anfrage in Zeit O(log n) zu beantworten erlaubt.