Priority search queues: Loser trees Advanced Algorithms & Data Structures Lecture Theme 06 Tobias Lauer Summer Semester 2006.

Slides:



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

Geometrische Datenstrukturen Haozhe Chen Aaron Richardson.
The difference between kein and nicht.
Peter Marwedel TU Dortmund, Informatik 12
Telling Time in German Deutsch 1 Part 1 Time in German There are two ways to tell time in German. There are two ways to tell time in German. Standard.
Wenn…… the conditional. Using the conditional tense The conditional tense is used to talk about something that happens only after something else happened.
Binäre Bäume Richard Göbel.
WS Algorithmentheorie 05 - Treaps Prof. Dr. Th. Ottmann.
NUMEX – Numerical experiments for the GME Fachhochschule Bonn-Rhein-Sieg Wolfgang Joppich PFTOOL - Precipitation forecast toolbox Semi-Lagrangian Mass-Integrating.
Wozu die Autokorrelationsfunktion?
Dumpline Status We have a leak of ~10 -4 mbar in the section inside the concrete shielding The leak is likely to be at a flange connection of the BPM (Ti/SS.
PageRank 1.What does the graph represent? 2.Describe PageRank. 3.What does PageRank measure in a graph? 4.Which role does PageRank play in IR?
FH-Hof Sortieren mit Binären Bäumen Richard Göbel.
This presentation is timed so you will only need to click on the left mouse button when it is time to move to the next slide. Right click on this screen.
Comparative Adjectives. The term comparison of adjectives is used when two or more persons or things have the same quality (height, size, color, any characteristic)
Das Perfekt Wiederholen (hoffentlich!). Think of 5 things you did in your holidays but think of sentences in the PRESENT TENSE. 1.Am Montag schlafe ich.
Adjektive Endungen von Frau Templeton.
Tag um Tag, Jahr um Jahr, Tag um Tag, Jahr um Jahr, Day by day, year by year, Wenn ich durch diese Straßen geh', When I go through these streets, Seh ich.
Was ich alles tun würde! All the things I would do!
You need to use your mouse to see this presentation © Heidi Behrens.
Relative clauses What is a relative clause?
Die Zeit (TIME) Germans are on military time which is 1-24
Institut AIFB, Universität Karlsruhe (TH) Forschungsuniversität gegründet 1825 Towards Automatic Composition of Processes based on Semantic.
| DC-IAP/SVC3 | © Bosch Rexroth Pneumatics GmbH This document, as well as the data, specifications and other information set forth in.
Das Perfekt (Present Perfect Tense). Think of 5 things you did in your holidays but think of sentences in the PRESENT TENSE. 1.Am Montag schlafe ich viel.
Deutsch 1 G Stunde. Dienstag, der 11. September 2012 Deutsch 1 (G Stunde)Heute ist ein E - Tag Unit: Introduction to German & Germany Objectives: Learn.
Deutsch 1 G Stunde. Donnerstag, der 25. Oktober 2012 Deutsch 1, G Stunde Heute ist ein B- Tag Unit: Family & homeFamilie & Zuhause Objectives: Phrases.
Deutsch 1 G Stunde. Donnerstag, der 18. Oktober 2012 Deutsch 1, G Stunde Heute ist ein E- Tag Unit: Family & homeFamilie & Zuhause Objectives: Phrases.
G Stunde DEUTSCH 1. Unit: Family & homeFamilie & Zuhause Objectives: Phrases about date, weather and time-telling Alphabet – pronunciation and words The.
Deutsch 1 G Stunde. Donnerstag, der 18. Oktober 2012 Deutsch 1, G Stunde Heute ist ein D- Tag Unit: Family & homeFamilie & Zuhause Objectives: Phrases.
Deutsch 1 G Stunde. Montag, der 10. September 2012 Deutsch 1 (G Stunde)Heute ist ein D - Tag Unit: Introduction to German & Germany Objectives: Introducing.
Donnerstag, den 28. November FUTURE HOLIDAYS Lernziel: to learn how to express future ideas. Starter: Finde ein Paar! will plane...zu werde hoffe...zu.
Wortschatz angenehm comfortable anstrengend tiring ausgezeichnet outstanding bequem comfortable berühmt famous besser better blöd stupid einfach easy fantastisch.
Die Zukunft The future I will.
The future tense with werden The verb werden werdensie / Sie werdetihr werdenwir wirder / sie / es wirstdu werdeich.
You need to use your mouse to see this presentation © Heidi Behrens.
You need to use your mouse to see this presentation © Heidi Behrens.
Wortschatz der Schulhof the playground die Aula the hall
From “Deutsch: Na Klar! 5th Edition”
DATIVE Ich schreibe meinem Bruder einen Brief.
Institut für Umweltphysik/Fernerkundung Physik/Elektrotechnik Fachbereich 1 K. Bramstedt, L. Amekudzi, J. Meyer IFE/IUP Tangent heights in occultation.
Verben Wiederholung Deutsch III Notizen.
Staatsballett Berlin Ein Verbesserungskonzept für den Social- Media Auftritt Your picture here.
The most obvious or direct use of auch is to mean also. Ich möchte auch Gitarre lernen. Auch ich möchte Gitarre lernen. I would like to learn Guitar. Someone.
The cheating verbs… (modal verbs). Modal Verb Chart wollenmüssenkönnenmögensollendürfenmöchten Ichwillmusskannmagsolldarfmöchte Duwillstmusstkannstmagstsollstdarfstmöchtest.
Hätte gern vs. Möchte gern
External Labels – The rules For all external labels the following rules apply (external labels are all labels which are not inside of a shape) - all labels.
Gestern hat mich ein Regentropfen getroffen Yesterday a rain drop met me. ;) und gab meinem Kopf einen nassen Kuss. And gave my head a wet kiss. Ohne Warnung,
By: Jade Bowerman. German numbers are quite a bit like our own. You start with one through ten and then you add 20, 30, 40 or 50 to them. For time you.
Alltagsleben Treffpunkt Deutsch Sixth Edition
Adjectiv Endungen Lite: Adjective following articles and pre-ceeding nouns. Colors and Clothes.
Future Tense. When is the future? Any time after the present…..so….any time after RIGHT NOW.
AVL-Trees (according to Adelson-Velskii & Landis, 1962) In normal search trees, the complexity of find, insert and delete operations in search.
Greetings and goodbyes Deutschland v. USA
Sentence Structure Subject and verb are always together. Subject and verb are always together. Subject and verb must agree Subject and verb must agree.
KIT – die Kooperation von Forschungszentrum Karlsruhe GmbH und Universität Karlsruhe (TH) Vorlesung Knowledge Discovery - Institut AIFB Tempus fugit Towards.
So ist das Leben Treffpunkt Deutsch Sixth Edition
DEUTSCHE VERBEN I. REGULAR VERBS.
Nur noch kurz die Welt retten Tim Bendzko
Separable Verbs Turn to page R22 in your German One Book R22 is in the back of the book There are examples at the top of the page.
Launch ON Global.vi System ID object name classname Services to suscribe Observer Control Ref vi-path Service name Step 1 : Objects register to the Global.vi´s,
1 Stevens Direct Scaling Methods and the Uniqueness Problem: Empirical Evaluation of an Axiom fundamental to Interval Scale Level.
Adjective Endings Nominative & Accusative Cases describing auf deutsch The information contained in this document may not be duplicated or distributed.
Selectivity in the German Mobility Panel Tobias Kuhnimhof Institute for Transport Studies, University of Karlsruhe Paris, May 20th, 2005.
By Martin L. Loeffler.  The basic sentence has a subject and a verb.  The subject and verb need to be together.  The subject and verb need to agree.
Adjective Declension in German
Der formelle Imperativ – the Imperative
Coordinating Conjunctions Why we need them & how to use them deutschdrang.com.
Memorisation techniques
Essay structure Example: Die fetten Jahre sind vorbei: Was passiert auf der Almhütte? Welche Bedeutung hat sie für jede der vier Personen? Intro: One or.
 Präsentation transkript:

Priority search queues: Loser trees Advanced Algorithms & Data Structures Lecture Theme 06 Tobias Lauer Summer Semester 2006

2 Intro 2 Recap Begriffe: Pennant, Top node Linien gestrichelt vs. durchgezogen

3 Special cases of insertion 1.The tree is empty. (trivial) 2.The key of the inserted node is larger than all other keys in the tree. Exercise 1

4 18, , , , , 7 1 9, , , , , , 3 9 1, , 13 5 Priority search pennant: example

5 Deletion of a point with key x Again, we must ensure that search-tree condition, semi-heap condition, and split-key condition are still fulfilled after the deletion. Follow the search path for x until the end. On the way down, remember… the node N containing x as its key the node S containing x as its split key If x is not contained in the tree, we are done. Otherwise, consider the last node E on the search path. Observe that… E has at most one child (otherwise, we could proceed further down). The split key of E is either x itself or the symmetric predecessor of x. (The symmetric predecessor of x is the largest key in the tree that is smaller than x.) Exchange the split keys of E and S (if E S) and remove E from the tree (replace it by its child if it has one).

6 Deletion of a point with key x Walk back the search path until N. At each node C on the way up: If the priority of C is smaller than that in E, exchange the points in E and C (but leave the split keys). Note that this may flip the dominated subtree of C but never destroys the semi-heap condition! Continue by the same method up the tree. If we arrive at N, exchange the points of N and E. Now E can be completely deleted.

7 18, , , , , 7 1 9, , , , , , 3 9 1, , 13 5 Example: delete(20)

8 18, , , , , 7 1 9, , , , , , 3 9 1, , 13 5 Example: delete(20) S N E

9 18, , , , , 7 1 9, , , , , , 3 9 1, , 13 5 Example: delete(20) S N E

10 18, , , , , 7 1 9, , , , , , 3 9 1, , 13 5 Example: delete(20) S N E

11 15, , , , , 7 1 9, , , , , , 3 9 1, , 13 5 Example: delete(20) S N E

12 10, , , , , 7 1 9, , , , , , 3 9 1, , 13 5 Example: delete(20) S N E

13 20, , , , , 7 1 9, , , , , , 4 9 1, , 13 5 Example: delete(20) S N E

14 4, , , , 7 1 9, , , , , , 4 9 1, , 13 5 Example: delete(20)

15 Analysis of delete We require one complete walk down the search path. Find N, S and E Then we walk up the same search path again (until N) Swap points if necessary. Running time: If the tree is balanced: How can we keep a priority search pennant balanced?

16 Balancing We always leave the top node as it is and only balance the loser tree. The loser tree is a standard binary tree. Binary trees can be balanced with different schemes Information for balancing must be kept in the nodes, e.g. height difference of subtrees (AVL trees) weight (#nodes) of the subtree (BB[α] trees, IPR balancing) color (red-black trees) If the tree is out of balance after an insertion or deletion, the balance is restored by restructuring the tree using rotations. Rotations preserve the search-tree property! But what about the semi-heap property?

17 5, 6 4 7, 3 9 Rotation t1t1 t2t2 t3t3 5, 6 4 7, 3 9 t1t1 t2t2 t3t3 Bad news: Rotation can destroy the semi-heap property! Good news: We can repair it!

18 2, 6 4 7, 3 9 1st case: x A s A and x B s B t1t1 t2t2 t3t3 2, 6 4 7, 3 9 t1t1 t2t2 t3t3 A B No repair needed!

19 5, 6 4 7, 3 9 2nd case: x A s A and x B > s B t1t1 t2t2 t3t3 7, 3 4 5, 6 9 t1t1 t2t2 t3t3 A B Swap!

20 3rd case: x A > s A and x B s B 2, , 3 9 t1t1 t2t2 t3t3 2, , 3 9 t1t1 t2t2 t3t3 2, , 6 9 t1t1 t2t2 t3t3 2, , 6 9 t1t1 t2t2 t3t3 Case 3a y A y B Case 3b y A > y B A B A B No repair needed!

21 4th case: x A > s A and x B > s B 7, , 3 9 t1t1 t2t2 t3t3 10, 3 4 7, 6 9 t1t1 t2t2 t3t3 7, , 6 9 t1t1 t2t2 t3t3 7, , 6 9 t1t1 t2t2 t3t3 A B A B Case 4a y A y B Case 4b y A > y B No repair needed! Swap!

22 Rotations Right rotation: Condition for swapping: x B > s B and y A y B Only one additional match is required Repair takes constant time! Left rotation: Symmetric condition Double rotations (left-right and right-left) Either: like two single rotations Or: Exercise 3

23 South-grounded range queries enumerateRectangle: Report all points of S inside the rectangle minXinRectangle: Find the leftmost point of S inside the rectangle maxXinRectangle: Find the rightmost point of S inside the rectangle minYinXRange: Find the bottommost point of S in a given x-range x left x right y top

24 MinXinRectangle Sei Min ein Zeiger auf den besten bisher gefundenen Knoten (zu Beginn setze Min auf einen Dummyknoten D mit x D = x max ). Beim Besuch von Knoten N: 1)Falls N der Suchbedingung genügt (x x N < x Min AND y N y), setze Min = N. 2)Besuche den linken Teilbaum, falls nötig, d.h. falls dieser existiert UND a)gültige x-Werte enthalten kann: s N x UND b)gültige y-Werte enthalten kann: y N y ODER N stammt aus seinem rechten Teilbaum (x N > s N ) 3)Besuche den rechten Teilbaum, falls nötig, d.h. falls dieser existiert UND d)gültige x-Werte enthalten kann: s N < x Min UND e)gültige y-Werte enthalten kann: y N y ODER N stammt aus seinem linken Teilbaum (x N s N ) Depth-first search (in preorder) with pruning

25 Analyse Definition: Ein bei minXinRectangle(x, x, y) inspizierter innerer Knoten N heißt potentiell verzweigend, wenn N bei seinem ersten Besuch alle der Bedingungen a-d erfüllt. N heißt (tatsächlich) verzweigend für minXinRectangle(x, x, y), wenn bei der Suche beide seiner Söhne inspiziert werden. Bemerkungen: (1) Für potentiell verzweigende Knoten N gilt immer y N y. (2) Jeder tatsächliche verzweigende Knoten ist auch potentiell verzweigend. (3) Umgekehrt muss jedoch nicht jeder potentiell verzweigende Knoten auch tatsächlich verzweigend sein.

26 Analyse Beobachtung 1: Wenn während minXinRectangle (x, x, y) im linken Teilbaum eines potentiell verzweigenden Knotens N ein neuer Knoten L mit y L y und x x L x Min gefunden wird, so ist N nicht tatsächlich verzweigend. Beobachtung 2: Für den Splitwert s N eines Knotens N, der bei einer Suchanfrage (x, x, y) potentiell verzweigend ist, gilt beim ersten Besuch von N: x s N < k Min. [Die Aussage ist die Zusammenfassung von (a) und (d).]

27 Verteilung verzweigender Knoten Lemma 1: Sei N ein verzweigender Knoten für minXinRectangle(x, x, y). Dann gibt es im rechten Teilbaum von N keine potentiell verzweigenden Knoten. Beweis: Da N verzweigend, ist x s N < x Min (s. Beobachtung 2). Annahme: R im rechten Teilbaum ist potentiell verzweigend, d.h. x s R < x Min xNsNxNsN xRsRxRsR sNsN sRsR xx Min

28 Beweis Lemma 1: Sei N ein verzweigender Knoten für minXinRectangle(x, x, y). Dann gibt es im rechten Teilbaum von N keine potentiell verzweigenden Knoten. 1. Fall: R stammt aus seinem linken Teilbaum (x R s R ) xNsNxNsN xRsRxRsR sNsN sRsR xx Min xRxR

29 Beweis xNsNxNsN xRsRxRsR sNsN sRsR x x Min xRxR xW xW xWxW Lemma 1: Sei N ein verzweigender Knoten für minXinRectangle(x, x, y). Dann gibt es im rechten Teilbaum von N keine potentiell verzweigenden Knoten. 2. Fall: R stammt aus seinem rechten Teilbaum (x R > s R )

30 Verteilung verzweigender Knoten Lemma 2: Trifft man bei minXinRectangle (x, x, y) im linken Teilbaum eines potentiell verzweigenden Knotens N auf einen weiteren potentiell verzweigenden Knoten L, so ist N nicht tatsächlich verzweigend. Beweis: Da N potentiell verzweigend ist, gilt x s N < x Min. Sei L im linken Teilbaum potentiell verzweigend, d.h. x s L < x Min xNsNxNsN xLsLxLsL sNsN sLsL xLxL xx Min xWxW xWxW

31 Verzweigende Knoten Lemma 1: Sei N verzweigender Knoten für minXinRectangle(x, x, y). Dann gibt es im rechten Teilbaum von N keine potentiell verzweigenden Knoten. Lemma 2: Trifft man bei minXinRectangle(x, x, y) im linken Teilbaum eines potentiell verzweigenden Knotens N auf einen weiteren potentiell verzweigenden Knoten L, so ist N nicht tatsächlich verzweigend. Satz 1: Bei einer MinXinRectangle-Suche (x, x, y) in einem Priority Search Pennant gibt es höchstens einen verzweigenden Knoten. (Formaler Beweis per Induktion über den Suchpfad)

32 Ergebnis Satz 2: Die Laufzeit der Min-X-in-Rectangle-Suche in einem Priority Search Pennant P der Höhe h ist durch O(h) beschränkt. Genauer gilt: Es werden höchstens 2 (h – 1) Knoten besucht. Ist P ein balancierter Priority Search Pennant mit n Elementen, so ist die Laufzeit der Min-X-in-Rectangle-Suche durch O(log n) beschränkt. Bemerkung: Priority Search Pennants sind also für die MinXinRectangle-Suche (asymptotisch) worst-case-optimal. (Denn schon die einfache Suche nach einem Schlüssel erfordert ja im worst case O(log n) Schritte.)

33 Andere Rechteckanfragen maxXinRectangle Analoger Beweis: O(log n) minYinXRange Ähnliche Argumentation über Verzweigung: O(log n) enumerateRectangle Beweis in Hinze (2001):O(r · (log n – log r +1)) wobei r die Anzahl der Punkte im Rechteck ist Bemerkung: Hier sind Priority Search Trees (McCreight, 1985) besser: O(log n + r)

34 References R. Hinze. A simply implementation technique for priority search queues. In Proceedings of the International Conference on Functional Programming (ACM ICFP01), pages Florence, Italy: ACM Press, E. M. McCreight. Priority search trees. In SIAM Journal on Computing, 14(2): May 1985.