Академический Документы
Профессиональный Документы
Культура Документы
Advanced Algorithms & Data Structures Lecture Theme 06 Tobias Lauer Summer Semester 2006
Overview
Motivation: a geometric problem South-grounded range queries Priority search queues Tournament trees Knockout tournaments Winner trees Loser trees Priority search pennants Insertion Deletion Balancing Range queries
ytop
xleft
xright
3
ytop
xleft
xright
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
4
Problem
Maintain a set P of points (x, y) such that the operations Insert a new point: insert(x,y) Find the point with given x-coordinate: lookup(x) Delete the point with given x-coordinate: delete(x) Find a point with minimum y-coordinate: accessmin() Delete a point with minimum y-coordinate: deletemin() South-grounded range queries enumerateRectangle(xleft , xright , ytop ) minXinRectangle(xleft , xright , ytop ) maxXinRectangle(xleft , xright , ytop ) minYinXRange(xleft , xright ) can be computed efficiently. This abstract data type is called priority search queue.
5
Tournament trees
Knockout tournament n = number of players Two players play one match until a winner is determined (no ties!) The loser drops out of the tournament The winner moves stays in the tournament The overall winner is the last player who is left (i.e. the only one who hasnt lost any match) Example: final round of football world cup* Number of matches played in a K.O. tournament with n players:
Italien 1
Italien 1
Niederlande 3
Argentinien 2
Italien 1
Niederlande 3
Spanien 4
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
Italien 1 I
Italien 1 D
Niederlande 3 P
Argentinien 2 A
Italien 1 F
Niederlande 3 N
Spanien 4 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
Italien 1 D
Niederlande 3 P
Argentinien 2 A
Italien 1 F
Niederlande 3 N
Spanien 4 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
10
Italien 1 I
Italien 1 D
Niederlande 3 P
Argentinien 2 A
Italien 1 F
Niederlande 3 N
Spanien 4 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
11
Italien 1 I
Niederlande 3 D P
Argentinien 2 A F N
Spanien 4 S
Deutschland 5
Frankreich 6
Polen 7
USA 8
12
Italien 1 I
Niederlande 3 D P
Argentinien 2 A F
Polen 7 N
Spanien 4 S
Deutschland 5
Frankreich 6
USA 8
13
Italien 1 I
Niederlande 3 D P
Argentinien 2 A
Frankreich 6 F
Polen 7 N
Spanien 4 S
Deutschland 5
USA 8
14
Italien 1 I
Argentinien 2 D
Niederlande 3 P
Frankreich 6 A F
Polen 7 N
Spanien 4 S
Deutschland 5
USA 8
15
Italien 1 I
Argentinien 2 D
Niederlande 3 P
Deutschland 5 A
Frankreich 6 F
Polen 7 N
Spanien 4 S
USA 8
16
Italien 1 I
Argentinien 2 D
Niederlande 3 P
Deutschland 5 A
Frankreich 6 F
Polen 7 N
Spanien 4 S
USA 8
17
Italien 1 I
Italien 1 D
Niederlande 3 P
Argentinien 2 A
Italien 1 F
Niederlande 3 N
Spanien 4 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
18
Italien 1 D
Niederlande 3 P
Argentinien 2 A
Italien 1 F
Niederlande 3 N
Spanien 4 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
19
Niederlande 3 I
Italien 1 D
Niederlande 3 P
Argentinien 2 A
Italien 1 F
Niederlande 3 N
Spanien 4 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
20
Niederlande 3 I
Argentinien 2 D
Spanien 4 P
Argentinien 2 A
Italien 1 F
Niederlande 3 N
Spanien 4 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
21
Niederlande 3 I
Argentinien 2 D
Spanien 4 P
Deutschland 5 A
Frankreich 6 F
Polen 7 N
USA 8 S
Argentinien 2
Deutschland 5
Frankreich 6
Italien 1
Niederlande 3
Polen 7
Spanien 4
USA 8
22
Niederlande 3 I
Argentinien 2 D
Spanien 4 P
Deutschland 5 A
Frankreich 6 F
Polen 7 N
USA 8 S
23
Niederlande 3 I
Argentinien 2 D
Spanien 4 P
Deutschland 5 A
Frankreich 6 F
Polen 7 N
USA 8 S
24
Italien 1 U
Niederlande 3 I
Argentinien 2 D
Spanien 4 P
Deutschland 5 A
Frankreich 6 F
Polen 7 N
USA 8 S
25
Niederlande 3 I
Argentinien 2 D
Spanien 4 P
Deutschland 5 A
Frankreich 6 F
Polen 7 N
USA 8 S
26
N, 3 I
A, 2 D
S, 4 P
D, 5 A
F, 6 F
P, 7 N
U, 8 S
A, 2
D, 5
F, 6
I, 1
N, 3
P, 7
S, 4
U, 8
27
Corollaries: 1. In each internal node, we find the loser of the match played between the winners of the left and right subtrees. 2. Each proper subtree contains all elements originating from that subtree except the winner.
28
7, 1 8
1, 2 4 5, 4 6 3, 8 3 2, 4 3, 8 4, 5 5, 4 6, 9 5 6, 9
4, 5 2 2, 4 1 1, 2
7, 1
29
30
1, 3 9
7, 8 4
10, 2 14
3, 4 1
9, 13 7
14, 8 13
20, 6 16
4, 10 3
13, 5 10
16, 4 15
18, 9 18
31
5, 2 5
1, 3 9
7, 8 4
10, 2 14
3, 4 1
9, 13 7
14, 8 13
20, 6 16
4, 10 3
13, 5 10
16, 4 15
18, 9 18
32
5, 2 9
7, 8 4
1, 3 5
10, 2 14
3, 4 1
9, 13 7
14, 8 13
20, 6 16
4, 10 3
13, 5 10
16, 4 15
18, 9 18
33
5, 2 9
1, 3 4
10, 2 14
3, 4 1
7, 8 5
9, 13 7
14, 8 13
20, 6 16
4, 10 3
13, 5 10
16, 4 15
18, 9 18
34
5, 2 9
1, 3 4
10, 2 14
3, 4 1
9, 13 7
14, 8 13
20, 6 16
4, 10 3
7, 8 5
13, 5 10
16, 4 15
18, 9 18
35
Analysis of insertion
If the key x is already in the tree, dont do anything Otherwise, create a new node N with pair (x, y) and x as the split key Walk down the search path for x, because (x, y) must end up in a node somewhere on that path If we encounter a node M whose priority yM is larger than yN and which originates from the same subtree to where the search path of x leads, then swap the pairs of the nodes M and N (but leave the split keys as they are). Continue by the same method until the end of the search path At the end of the search path, insert N as the appropriate child (as dictated by the search tree condition)
36
References
R. Hinze. A simply implementation technique for priority search queues. In Proceedings of the International Conference on Functional Programming (ACM ICFP01), pages 110-121. Florence, Italy: ACM Press, 2001. E. M. McCreight. Priority search trees. In SIAM Journal on Computing, 14(2):257-276. May 1985.
37