Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer...
-
Upload
sofie-heino -
Category
Documents
-
view
104 -
download
0
Transcript of Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer...
![Page 1: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/1.jpg)
Institut für Kartographie und Geoinformation
Diskrete Mathematik IVorlesung 8
02.12.99
-Binärer Suchbaum II-
![Page 2: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/2.jpg)
2
Übersicht
• Binärer Suchbaum– Suchen von Knoten– Löschen von Knoten (Wurzel)– Durchlaufstrategien
• Preorder• Breitendurchlauf
![Page 3: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/3.jpg)
3
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 4: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/4.jpg)
4
Suchen von Knoten
Suche einer Zahl k in einem binären Suchbaum B
• B ist leer– k kann nicht im Baum sein.
• B ist nicht leer– B.wert = k : k ist gefunden, d.h. bereits in B vorhanden.– B.wert < k : Suche im rechten Unterbaum von B.– B.wert > k : Suche im linken Unterbaum von B.
![Page 5: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/5.jpg)
5
Löschen von Knoten (Wurzel)
149
10
16
13 15
• Rechter Unterbaum ist unbesetzt
![Page 6: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/6.jpg)
6
Löschen von Knoten (Wurzel)
• Rechter Unterbaum ist unbesetzt
Unterbaum bildeteinen
binären Baum
149
10
13 15
![Page 7: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/7.jpg)
7
Löschen von Knoten (Wurzel)
18149
10 24
16
13 15
• Beide Unterbäume sind besetzt
![Page 8: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/8.jpg)
8
Löschen von Knoten (Wurzel)
• Beide Unterbäume sind besetzt
Suchbaum zerfällt inzwei disjunkte Bäume
Es muß eine neuer Knoten, der dieWurzel bildet, gefunden werden.
149
10
13 15
18
24
![Page 9: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/9.jpg)
9
Löschen von Knoten (Wurzel)
18149
10 24
16
13 15
• Beide Unterbäume sind besetzt
Kriterien:Der Knoten muß größer sein, als die Wurzel des linken Unterbaums.
Der Knoten muß kleiner sein als die Wurzel des rechten Unterbaums.
![Page 10: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/10.jpg)
10
Löschen von Knoten (Wurzel)
18149
10 24
16
13 15
• Beide Unterbäume sind besetzt
Kandidaten
![Page 11: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/11.jpg)
11
Löschen von Knoten (Wurzel)
18149
10 24
15
13
• Beide Unterbäume sind besetzt
![Page 12: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/12.jpg)
12
Durchlaufstrategien
• Preorder– Die Wurzel wird vor den Unterbäumen besucht,
die Unterbäume werden von links nach rechts abgearbeitet
• Breitendurchlauf– Mit einem Knoten werden seine Nachbarn
von links nach rechts besucht
![Page 13: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/13.jpg)
13
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
![Page 14: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/14.jpg)
14
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16
![Page 15: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/15.jpg)
15
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10
![Page 16: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/16.jpg)
16
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10, 9
![Page 17: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/17.jpg)
17
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10, 9, 14
![Page 18: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/18.jpg)
18
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10, 9, 14, 13
![Page 19: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/19.jpg)
19
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10, 9, 14, 13, 15
![Page 20: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/20.jpg)
20
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10, 9, 14, 13, 15, 24
![Page 21: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/21.jpg)
21
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10, 9, 14, 13, 15, 24, 18
![Page 22: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/22.jpg)
22
Durchlaufstrategie: Preorder
18149
10 24
16
13 15
16, 10, 9, 14, 13, 15, 24, 18
![Page 23: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/23.jpg)
23
Durchlaufstrategie: Preorder
void PreOrder() { PreOrder(wurzel);}private void PreOrder(Knoten aktuell) { if (aktuell != null) { System.out.println(aktuell.GibWert()); PreOrder(aktuell.GibLinks()); PreOrder(aktuell.GibRechts()); }}
![Page 24: Institut für Kartographie und Geoinformation Diskrete Mathematik I Vorlesung 8 02.12.99 -Binärer Suchbaum II-](https://reader036.fdocument.pub/reader036/viewer/2022062512/55204d7e49795902118cf331/html5/thumbnails/24.jpg)
Schönen Dank für Ihre Aufmerksamkeit und
Auf Wiedersehen