Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II...

87
Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001

Transcript of Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II...

Page 1: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer

AVL-Bäume

Geoinformation IIVorlesung 2

SS 2001

Page 2: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

2 2

Übersicht I

• Einfacher Segmentschnitt I• Verwaltung der aktiven Elemente• letzte Stunde• zur Erinnerung: Algorithmus Scan-Line• Datenstrukturen für T und S• Binärer Suchbaum• Exkurs: AVL-Bäume• AVL-Baum (Definition)• AVL-Baum: Beispiel• Balancefaktor

Page 3: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

3 3

Übersicht II

• AVL-Baum: Beispiel• Einfügen von Knoten• Löschen von Knoten• L-Rotation• LR-Rotation• Exkurs: AVL-Bäume in Kürze• Vollständige Bäume• Minimale Knotenanzahl von AVL-Bäumen• Fibonacci-Zahlen

Page 4: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

4 4

Übersicht III

• Minimale Knotenanzahl von AVL-Bäumen• Maximale Höhe von AVL-Bäumen• Das Wichtigste zu AVL in Kürze• 4 Fälle im Überblick• Zurück zur GIS Vorlesung• Eine Variante des AVL-Baums• für die Haltepunkte ...

Page 5: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

5 5

Einfacher Segmentschnitt I

S1 = det ( P1,P3,P4) Def.: Vor.: Alle Determinanten sind 0:S2 = det ( P3,P1,P2) g und g` schneiden sich genau dann, wenn S1, S2

S3 = det ( P2,P3,P4) sowie S3, S4 jeweils verschiedene Vorzeichen S4 = det ( P4,P1,P2) haben.

P2

P1

P3 P4

P2

P3

P4

P1g

g`

P2

P1

P3

P4

Page 6: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

6 6

Verwaltung der aktiven Elemente

A

BF

C

D

ES1

S3

S2

S4

B

EC

D

Page 7: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

7 7

letzte Stunde

• Scan-Line• Hauptideen

– Projektion auf x-Achse– Beschränkung auf aktive Elemente– Ordnung der aktiven Elemente durch Scan-Line– Beschränkung auf Nachbarn

• zum Schluß: 2-Segment-Schnitt(müßte Ihnen bekannt sein)

• heute: – Datenstrukturen für Scan-Line– Polygon-Overlay

Page 8: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

8 8

zur Erinnerung: Algorithmus Scan-Line

Input:

S: eine Menge von Segmenten

Output:

die Schnittpunkte der Elemente von S

Sei

T = Endpunkte der Segmente von S nach x-Koordinaten sortiert (Haltepunkte)

L = // aktive Segmente von S

while T do

bestimme und entferne den nächsten Punkt pT

x ist x-Koordinate von p

case: p ist linker Endpunkt von sfuege_ein(s,x,L)sl = vorgaenger(s,x,L)sr = nachfolger(s,x,L)

schnitt(sl,s,T);

schnitt(s,sr,T);

p ist rechter Endpunkt von s

sl = vorgaenger(s,x,L)sr = nachfolger(s,x,L)

entferne(s,x,L)

schnitt(sl,sr,T)

p ist Schnittpunkt von s und t

vertausche(s,t,L,x) // t < ssl = vorgaenger(t,x,L)sr = nachfolger(s,x,L)

schnitt(sl,t,T)

schnitt(s,sr,T)

Page 9: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

9 9

Datenstrukturen für T und S

• Datenstrukur für T– AVL-Baum

– siehe diskrete Mathematik

• zur Erinnerung: was ist ein AVL-Baum– erstens ein Suchbaum

– und zwar ein ausgeglichener Suchbaum

• Datenstruktur für L– AVL-Baum?

– Vorgänger und Nachfolger

– Variante des AVL-Baums

• alle Informationen sind in Blättern (nicht in inneren Knoten)

• die Blätter bilden eine doppelt verkettete Liste

Page 10: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

10 10

Binärer Suchbaum

• Ein binärer Baum B ist ein binärer Suchbaum, falls er leer ist oder die folgenden Eigenschaften erfüllt sind:

– die beiden Unterbäume sind binäre Suchbäume– die Beschriftungen der Knoten des linken Suchbaums sind

kleiner als die Beschriftung der Wurzel– die Beschriftungen des rechten Suchbaums sind größer als

die Beschriftung der Wurzel

n

<n >n

Page 11: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer

Exkurs: AVL-Bäumesiehe Vorlesung Nr. 9

Diskrete Mathe I

Page 12: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

12 12

AVL-Baum (Definition)

Ein binärer Baum heißt ausgeglichener Baum oder

AVL-Baum (nach Adelson-Velskij und Landis), falls

sich für jeden Knoten k die Höhen h der beiden

Teilbäume um höchstens 1 unterscheiden.

Page 13: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

13 13

AVL-Baum: Beispiel

Page 14: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

14 14

Balancefaktor

Balancefaktor bal(k)

bal(k) = h(rechter Teilbaum von k) -

h(linker Teilbaum von k)

Für AVL-Bäume gilt:

bal(k) { 1,0, 1}

Page 15: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

15 15

AVL-Baum: Beispiel

0 0

0

+1

+1-1

+1

Page 16: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

16 16

AVL-Baum: Beispiel

0 0

0

+1

+1-1

+1

Page 17: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

17 17

0

0

+1

+10

+2

AVL-Baum: Beispiel

Page 18: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

18 18

Einfügen von Knoten

26 39

17113

208

33

14

00

00 0 0

0 +1

+1Einfügen von k = 30

Page 19: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

19 19

14

113

8

00

0

26 39

17

20

33

00

0 0

+1

Einfügen von Knoten

Einfügen von k = 30 +1

Page 20: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

20 20

14

113

8

00

0

26 39

17

20

33

00

0 0

+1

Einfügen von Knoten

Einfügen von k = 30 +1

Page 21: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

21 21

17

20

14

0

26 39

33

00

0113

8

00

0 +1

Einfügen von Knoten

Einfügen von k = 30 +1

Page 22: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

22 22

17

20

14

0

26 39

33

00

0113

8

00

0 +1

Einfügen von Knoten

Einfügen von k = 30 +1

Page 23: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

23 23

14

30

26 39

33

00

0113

8

00

0

17

20

0

+1

0

Einfügen von Knoten

Einfügen von k = 30 +1

Page 24: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

24 24

14

+1

113

8

00

0

17

20

0

+1

30

26 39

33

0

0

0

Einfügen von Knoten

Einfügen von k = 30 +1

Page 25: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

25 25

17

20

14

0113

8

00

0 +1

-1

26 39

33

30

0+1

0

Einfügen von Knoten

Einfügen von k = 30 +1

Page 26: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

26 26

17

20

14

0113

8

00

0 +2

26 39

33

30

0+1

-1

0

Ausgeglichenheit ist verletzt

Einfügen von Knoten

Einfügen von k = 30 +1

Page 27: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

27 27

17

20

14

0113

8

00

0 +2

26 39

33

30

0+1

-1

0

Ausbalancierendurch Rotation

Einfügen von Knoten

Einfügen von k = 30 +1

Page 28: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

28 28

26 39

17113

208

33

14

30

0+1

00 0 -1

0 +2

0

Einfügen von Knoten

R- Rotation

Einfügen von k = 30 +1

Page 29: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

29 29

17

20

14

0113

8

00

0 +2

26 39

33

30

0+1

-1

0

Einfügen von Knoten

Einfügen von k = 30 +1

Page 30: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

30 30

26 39

17113

208

33

14

30

0+1

00 0 -1

0 +2

0

Einfügen von Knoten

Einfügen von k = 30 +1

Page 31: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

31 31

17

20

14

0113

8

00

0 +2

26

30 39

33L- Rotation

Einfügen von Knoten

Einfügen von k = 30 +1

Page 32: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

32 32

17

20

26

14

0113

8

00

0 +2

30 39

33

Einfügen von Knoten

Einfügen von k = 30 +1

Page 33: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

33 33

17113

208

26

14

00 0

0 +2

30 39

33

Einfügen von Knoten

Einfügen von k = 30 +1

Page 34: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

34 34

26

14

113

8

00

0 0

Einfügen von Knoten

Einfügen von k = 30

39

20 33

00

0 0

017 30

+1

Page 35: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

35 35

113

268

14

0

00

0 0

17

Einfügen von Knoten

Einfügen von k = 30

39

20 33

0

0 0

030

+1

Page 36: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

36 36

39

20113

268

33

14

00

00 0 0

0 0

017 30

Einfügen von Knoten

+1

Page 37: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

37 37

Löschen von Knoten

26 39

17113

208

33

14

00

00 0 0

0 +1

+1Löschen von k = 8

Page 38: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

38 38

Löschen von Knoten

26 39

17113

208

33

14

00

00 0 0

0 +1

+1Löschen von k = 8

Page 39: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

39 39

Löschen von Knoten

113

8

14

00

0

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 8

Page 40: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

40 40

Löschen von Knoten

3

14

0

11-1

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 8

Page 41: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

41 41

Löschen von Knoten

3

14

0

11-1

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 8

Page 42: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

42 42

Löschen von Knoten

3

14

0

11-1

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 8

Page 43: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

43 43

Löschen von Knoten

3

14

0

11-1

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 11

Page 44: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

44 44

Löschen von Knoten

3

14

0

11-1

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 11

Page 45: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

45 45

Löschen von Knoten

3

14

0

11-1

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 11

Page 46: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

46 46

Löschen von Knoten

14

30

26 39

17

20

33

00

0 0

+1

+1Löschen von k = 11

Page 47: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

47 47

Löschen von Knoten

14

30

26 39

17

20

33

00

0 0

+1

+2Löschen von k = 11

L- Rotation

Page 48: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

48 48

Löschen von Knoten

14

30

26 39

17

20

33

00

0 0

+1

+2Löschen von k = 11

Page 49: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

49 49

Löschen von Knoten

14

30

26 39

17

20

33

00

0 0

+1

+2Löschen von k = 11

Page 50: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

50 50

20

173

14

00

0

26

33

390 0

0

0

Löschen von Knoten

Page 51: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

51 51

26173

3314

39

20

00 0 0

0 0

0

Löschen von Knoten

Page 52: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

52 52

L-Rotation

Knoten x wird eingefügt und verletzt dadurch die

Ausgeglichenheit an einem höher gelegenen Knoten k1

Notwendige Korrektur durch L-Rotation (symmetrisch:

R-Rotation): Umhängen von zwei Kanten

Page 53: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

53 53

L-Rotation

T1

T2 T3

k1

k2

0

+1

Page 54: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

54 54

L-Rotation

T1

T2 T3

k1

k2

x

+1

+2

Page 55: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

55 55

L-Rotation

T1

T2 T3

k1

k2

x

+1

+2

Page 56: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

56 56

L-Rotation

T1

T2 T3

k1

k2

x

+1

+2

Page 57: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

57 57

L-Rotation

T1

k1

k2

x

0

T2

T3

0

Page 58: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

58 58

LR-Rotation

x wird eingefügt und verletzt dadurch die Ausgeglichen-

heit an einem höher gelegenen Knoten k1.

Notwendige Korrektur durch LR- Rotation

(symmetrisch: RL-, RR- und LL- Rotation):

Umhängen von vier Kanten

Page 59: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

59 59

LR-Rotation

T1

k2

k10

-1

T3

T4

k3

T2

0

Page 60: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

60 60

LR-Rotation

T1

k2

k1

x

+1

-2

T3

T4

k3

T2

+1

Page 61: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

61 61

LR-Rotation

k1

-2

T4

T1

k2

x

+1

T3

k3

T2

+1

Page 62: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

62 62

LR-Rotation

k1

-2

T1

k2

x

+1

T3

T4

k3

T2

+1

Page 63: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

63 63

LR-Rotation

T1

k2

k1

x

+1

-2

T3

T4

k3

T2

+1

Page 64: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

64 64

LR-Rotation

k1

-2

T4

T1

k2

x

-1

T3

k3

T2

-1

Page 65: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

65 65

LR-Rotation

k1

-2

T1

k2

x

-1

T3T4

k3

T2

-1

Page 66: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

66 66

LR-Rotation

T1

k2

k1

x

-1

-2

T3T4

k3

T2

-1

Page 67: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

67 67

LR-Rotation

T1

k2

k1

x

0

0

T3

T4

k3

T2

-1

Page 68: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer

Exkurs: AVL-Bäume in Kürze

siehe Vorlesung Nr. 10

Diskrete Mathe I

Page 69: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

69 69

Übersicht

• Vollständige Bäume• Minimale Knotenanzahl von AVL-Bäumen

– Fibonacci-Zahlen

• Maximale Höhe von AVL-Bäumen• Das Wichtigste zu AVL in Kürze• 4 Fälle im Überblick• „Überleitung“• Güte von Algorithmen• Groß-Oh-Notation• Inklusion• Komplexität - Beispiele

Page 70: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

70 70

Vollständige Bäume

Ein binärer Baum heißt vollständig, wenn alle Blätter die gleiche Höhe haben.

Ein vollständiger binärer Baum gegebener Höhe enthält die maximale Anzahl von Knoten.

Wie groß ist die maximale Anzahl der Knoten eines vollständigen Baumes gegebener Höhe?

Page 71: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

71 71

Vollständige Bäume

Baum Höhe Anzahl

innere Knoten Blätter

1

3

0

1

3

1

2

4

h 2h-1-1 2h-1

= 2h-1

... ... ...

2

Page 72: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

72 72

Vollständige Bäume

Satz: Ein vollständiger binärer Baum der Höhe h enthält 2h-

1 Blätter und 2h-1 Knoten*(innere Knoten + Blätter!).

Beweis: 1) Induktionsanfang: h= 1

Der Baum besteht nur aus der Wurzel, die auch das einzige Blatt ist:

21-1 = 20 = 1 Blatt21-1 = 2 - 1 = 1 Knoten

2) Induktionsschritt: h h + 1

Höhe h Höhe h + 1

2h-1 Blätter 2h Blätter

2h-1 Knoten 2h-1 innere Knoten

2h + 2h - 1 = 2h+1-1

Page 73: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

73 73

Minimale Knotenanzahl von AVL-Bäumen

N(h) sei die minimale Anzahl von Knoten eines AVL- Baumes der Höhe h.

h = 1 N(1) = 1

h = 2 N(2) = 2

h = 3 N(3) = 4

Page 74: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

74 74

Minimale Knotenanzahl von AVL-Bäumen

Allgemeiner Fall:

N(h-2)N(h-1)

1

worst case der Höhe h: N(h) = N(h-1) + N(h-2) + 1

Page 75: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

75 75

Fibonacci-Zahlen

fib(0) = 0

fib(1) = 1

fib(2) = 1...fib(n) = fib(n-1) + fib(n-2)

Abschätzung von fib: Sei

1 5

21,618

1 5

20,618

fib(n) 1

5n n

Page 76: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Satz: N(h) = fib(h+2) - 1

Beweis:

1) Induktionsanfang: h = 1

fib(1+2) - 1 = fib(3) - 1 = 2 - 1 = 1

N(h)N(h-1)

1 N(h+1) = 1 + N(h) + N(h-1)

= 1+ fib(h+2) - 1 + fib(h+1) - 1

= fib(h+3) - 1

= fib([h+1]+2) - 1

2) Induktionsschritt: h h + 1

Minimale Knotenanzahl von AVL-Bäumen

Page 77: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

77 77

Daraus folgt nach Umformung der Abschätzung:

Ein AVL-Baum mit n Knoten hat höchstens die Höhe

1,44... log(n) + const

Maximale Höhe von AVL-Bäumen

Page 78: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

78 78

Das Wichtigste zu AVL in Kürze

1. Die { L, R, RL, LR } - Rotationen finden Anwendung, wenn bei der Rückkehr von den eingefügten/gelöschten Knoten zur Wurzel des Baumes ein Balance-Faktor {-2, +2 } gefunden wird.

2. Die Wiederherstellung der AVL-Eigenschaft involviert höchstens 3 Knoten + Verweise auf die Nachfolger. Prinzip der Lokalität

(Das Problem kann auch nur auf dem Weg von einem Blatt zur Wurzel des Baumes auftreten.)

3. Es finden nur vertikale Verschiebungen der involvierten Knoten statt.

Page 79: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

79 79

Das Wichtigste zu AVL in Kürze

Die Form eines Baumes hängt von der Eingabefolge ab:

Eingabe von {1, 2, 3}

Eingabefolge: 2, 1, 3

2

1 3

Eingabefolge: 2, 3, 12

1 3

Page 80: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

80 80

Das Wichtigste zu AVL in Kürze

Eingabefolge: 1, 2, 3

1

2

3

2

1 30

1

2

L-Rotation

Page 81: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

81 81

Das Wichtigste zu AVL in Kürze

Eingabefolge: 3, 2, 1

2

1 3

1

2

3R-Rotation

-2

Page 82: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

82 82

Das Wichtigste zu AVL in Kürze

Eingabefolge: 3, 1, 2

2

1 3

1

2

3

1

2

3

L-R-Rotation

2 2

L

R

Page 83: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

83 83

Das Wichtigste zu AVL in Kürze

Eingabefolge: 1, 3, 2

2

1 33

2

1

3

2

1

R-L-Rotation

2 2

R

L

Page 84: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

84 84

4 Fälle im Überblick

Woher rührt die Verletzung der Balance am Knoten ?

R LR RL L

Page 85: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Institut für Kartographie und GeoinformationProf. Dr. Lutz Plümer

Zurück zur GIS Vorlesung

Page 86: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

86 86

Eine Variante des AVL-Baums

• mit einer doppelt verketteten Liste der Blätter

für die Menge der aktiven Elemente

Page 87: Institut für Kartographie und Geoinformation Prof. Dr. Lutz Plümer AVL-Bäume Geoinformation II Vorlesung 2 SS 2001.

Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2 Lutz Plümer - Geoinformation - 6. Semester - SS 2001 - Vorlesung 2

87 87

für die Haltepunkte ...

• ...mit den Operationen– Einfügen eines gefundenen Schnittpunktes– Finden und Entfernen des nächsten (also minimalen)

Elements ...

• ... genügt ein „normaler“ AVL-Baum• obwohl man mit Kanonen auf Spatzen schießt• besser: ein Heap• bei Interesse: Vorlesung 2 (heute),

Diskrete Mathematik