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

Slides:



Advertisements
Ähnliche Präsentationen
Prof. Dr. S. Albers Prof.Dr.Th Ottmann
Advertisements

Christian Schindelhauer
Algorithmen und Datenstrukturen
3. Kapitel: Komplexität und Komplexitätsklassen
Kapitel 3: Listen Lineare Liste: endliche Folge von Elementen eines Grundtyps (n>=0), leere Liste falls n=0 Listenelemente besitzen.
Synonyme: Stapel, Keller, LIFO-Liste usw.
Gliederung Motivation / Grundlagen Sortierverfahren
WS Algorithmentheorie 13 - Kürzeste (billigste) Wege Prof. Dr. Th. Ottmann.
Funktionenklassen zur Messung der Komplexität
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (02 – Funktionenklassen) Prof. Dr. Th. Ottmann.
Algorithmen und Datenstrukturen
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (23 – Sortieren vorsortierter Daten) Prof. Th. Ottmann.
Algorithmen und Datenstrukturen
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (03 – Verschiedene Algorithmen für dasselbe Problem) Prof. Dr. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (13 – Offenes Hashing) Prof. Th. Ottmann.
Algorithmen und Datenstrukturen
Prof. Dr. S. Albers Prof. Dr. Th. Ottmann
Algorithmen und Datenstrukturen
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 24 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Algorithmen und Datenstrukturen
Halbzeit: Kurze Wiederholung
Sortieren vorsortierter Daten
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (03 – Verschiedene Algorithmen für dasselbe Problem) Prof. Dr. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (02 – Funktionenklassen) Prof. Dr. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen Halbzeit: Was haben wir bisher gelernt? Prof. Th. Ottmann.
Algorithmen und Datenstrukturen
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 19 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 9 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 4 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Anwendungen von Stapeln und Schlangen
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (21 - AVL-Bäume: Entfernen, Bruder-Bäume) Prof. Th. Ottmann.
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 2 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (11-3 –Selbstanordnende lineare Listen) Prof. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (11-1 –Selbstanordnende lineare Listen) Prof. Th. Ottmann.
Online Competitive Algorithms
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (27-Selbstanordnende lineare Listen) Prof. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (15 Hashverfahren: Verkettung der Überläufer) Prof. Th. Ottmann.
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (21 – Kürzeste Wege) T. Lauer.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (12 – Dynamische Tabellen) Prof. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (14 Amortisierte worst-case-Analyse Beispiel: Bitwechselkosten eines Dualzählers) Prof. Th. Ottmann.
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (17 – Fibonacci-Heaps – Analyse) Tobias Lauer.
Algorithmen und Datenstrukturen
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (20 - AVL-Bäume: Entfernen, Bruder-Bäume) Prof. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (07 - Skiplisten) Prof. Th. Ottmann.
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 12 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Union-Find-Strukturen
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (03 – Verschiedene Algorithmen für dasselbe Problem) Prof. Dr. Th. Ottmann.
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 16 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Algorithmen und Datenstrukturen
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (05 – Elementare Datenstrukturen) Prof. Th. Ottmann.
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 6 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

EINI-I Einführung in die Informatik für Naturwissenschaftler und Ingenieure I Kapitel 11 Claudio Moraga, Gisbert Dittrich FBI Unido
EINI-I Einführung in die Informatik für Naturwissenschaftler und Ingenieure I Vorlesung 2 SWS WS 99/00 Gisbert Dittrich FBI Unido
Kapitel 2: Datenstrukturen
PRJ 2007/1 Stefan Dissmann Verkettete datenstruktur: Liste Problem: Liste, die eine beliebige Zahl von Elementen verwaltet Operationen: Erzeugen, Anfügen,
Splay Trees Von Projdakov Benjamin.
Einführung in die Programmierung
Effiziente Algorithmen
Diskrete Mathematik II
Effiziente Algorithmen
Effiziente Algorithmen Hartmut Klauck Universität Frankfurt SS
Einführung in die Informatik für Naturwissenschaftler und Ingenieure (alias Einführung in die Programmierung) (Vorlesung) Prof. Dr. Günter Rudolph Fachbereich.
Einführung in die Programmierung Wintersemester 2009/10 Prof. Dr. Günter Rudolph Lehrstuhl für Algorithm Engineering Fakultät für Informatik TU Dortmund.
Einführung in die Informatik für Naturwissenschaftler und Ingenieure (alias Einführung in die Programmierung) (Vorlesung) Prof. Dr. Günter Rudolph Fachbereich.
1.6 Die Datenstruktur Stapel Ein Stapel (Stack) ist ein Sonderfall einer Liste. Die Elemente werden nach dem Prinzip LIFO (Last In First Out) angefügt.
Einfach und doppelt verkettete Listen in JAVA by Jens Weibler
Institut für Wirtschaftsinformatik – Software Engineering, JKU Linz 1 Thomas Hilpold: Algorithmen und Datenstrukturen SS 2005 Mag.Th. Hilpold u. Dr. A.Stritzinger.
Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer Diskrete Mathematik II Vorlesung Datenstrukturen für den Algorithmus von.
Tutorium Software-Engineering SS14 Florian Manghofer.
 Präsentation transkript:

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

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann2 Dynamische Tabellen Problem: Verwaltung einer Tabelle unter den Operationen Einfügen und Entfernen, so dass die Tabellengröße der Anzahl der Elemente angepasst werden kann, immer ein konstanter Anteil der Tabelle mit Elementen belegt ist, die Kosten für n Einfüge- oder Entferne-Operationen O(n) sind. Organisation der Tabelle: Hashtabelle, Heap, Stack, etc. Belegungsfaktor T : Anteil der Tabellenplätze von T, die belegt sind. Kostenmodell: Einfügen oder Entfernen eines Elementes verursacht Kosten 1, wenn Tabelle noch nicht voll. Wird Tabellengröße geändert, müssen zunächst alle Elemente kopiert werden.

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann3 Initialisierung class dynamicTable { private int [] table; private int size; private int num; dynamicTable () { table = new int [1];//Initialisierung leere Tabelle size = 1; num = 0; }

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann4 Vergrößerungsstrategie: Einfügen Verdoppele Tabellengröße, sobald versucht wird, in bereits volle Tabelle einzufügen! public void insert (int x) { if (num == size) { int[] newTable = new int[2*size]; for (int i=0; i < size; i++) fuege table[i] in newTable ein; table = newTable; size = 2*size; } fuege x in table ein; num = num + 1; }

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann5 Einfüge-Operationen in eine anfangs leere Tabelle t i = Kosten der i-ten Einfüge-Operation Worst case: t i = 1, falls die Tabelle vor der Operation i nicht voll ist t i = (i – 1) + 1, falls die Tabelle vor der Operation i voll ist. Also verursachen n Einfüge-Operationen höchstens Gesamtkosten von Amortisierter Worst-Case: Aggregat -, Bankkonto -, Potential-Methode

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann6 Potential-Methode T Tabelle mit k = T.num Elementen und s = T.size Größe Potentialfunktion (T) = 2 k – s

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann7 Eigenschaften der Potentialfunktion Eigenschaften 0 = (T 0 ) = ( leere Tabelle ) = -1 Für alle i 1 : i = (T i ) 0 Weil n gilt, ist a i eine obere Schranke für t i Unmittelbar vor einer Tabellenexpansion ist k = s, also (T) = k = s. Unmittelbar nach einer Tabellenexpansion ist k = s/2, also (T) = 2k – s = 0.

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann8 Amortisierte Kosten des Einfügens (1) k i = # Elemente in T nach der i-ten Operation s i = Tabellengröße von T nach der i-ten Operation Fall 1: [ i-te Operation löst keine Expansion aus]

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann9 Fall 2: [ i-te Operation löst Expansion aus] Amortisierte Kosten des Einfügens (2)

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann10 Einfügen und Entfernen von Elementen Jetzt: Kontrahiere Tabelle, wenn Belegung zu gering! Zíele: (1) Belegungsfaktor bleibt durch eine Konstante nach unten beschränkt (2) amortisierte Kosten einer einzelnen Einfüge- oder Entferne- Operation sind konstant. 1. Versuch Expansion: wie vorher Kontraktion: Halbiere Tabellengröße, sobald Tabelle weniger als ½ voll ist (nach Entfernen)!

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann11 Schlechte Folge von Einfüge- und Entferne- operationen Kosten n/2 mal Einfügen (Tabelle voll) 3 n/2 I: Expansionn/2 + 1 D, D: Kontraktionn/2 + 1 I, I : Expansionn/2 + 1 D, D: Kontraktion Gesamtkosten der Operationsfolge: I n/2, I,D,D,I,I,D,D,... der Länge n sind

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann12 2. Versuch Expansion: Verdoppele die Tabellengröße, wenn in die volle Tabelle eingefügt wird. Kontraktion: Sobald der Belegungsfaktor unter ¼ sinkt, halbiere die Tabellengröße. Folgerung: Die Tabelle ist stets wenigstens zu ¼ voll, d.h. ¼ (T) 1 Kosten einer Folge von Einfüge- und Entferne-Operationen?

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann13 Analyse Einfügen und Enfernen k = T.num, s = T.size, = k/s Potentialfunktion

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann14 Analyse Einfügen und Entfernen Unmittelbar nach einer Expansion oder Kontraktion der Tabelle: s = 2k, also (T) = 0

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann15 Einfügen i-te Operation: k i = k i Fall 1: i-1 ½ Fall 2: i-1 < ½ Fall 2.1: i < ½ Fall 2.2: i ½

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann16 Einfügen Fall 2.1: i-1 < ½, i < ½ (keine Expansion) Potentialfunktion

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann17 Einfügen Fall 2.2: i-1 < ½, i ½ (keine Expansion) Potentialfunktion

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann18 Entfernen k i = k i Fall 1: i-1 < ½ Fall1.1: Entfernen verursacht keine Kontraktion s i = s i-1 Potentialfunktion

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann19 Entfernen Fall 1.2: i-1 < ½ Entfernen verursacht Kontraktion 2s i = s i –1 k i-1 = s i-1 /4 k i = k i Fall 1: i-1 < ½ Potentialfunktion

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann20 Entfernen Fall 2: i-1 ½ keine Kontraktion s i = s i –1 k i = k i Fall2.1: i-1 ½ Potentialfunktion

Informatik II: Algorithmen und Datenstrukturen, SS 2008 Prof. Dr. Thomas Ottmann21 Entfernen Fall 2: i-1 ½ keine Kontraktion s i = s i –1 k i = k i Fall2.2: i < ½ Potentialfunktion