SlideShare a Scribd company logo
14   	
 




2011   7   8
OK



                    (^^)b




2011   7   8
14
               14.1              O(n)




                           (i   ) O(lgn)


               14.2

                    14.1


               14.3




2011   7   8
3                                                              size
               1


                            14.1 Dynamic order statistics                                                     303
                                Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shade
                                and darkened nodes are black. In addition to its usual fields, each node x has a field
                                                                    26
                                the number of nodes in the subtree rooted at x.
                                                                    20
                                                17                                               41
                                                12                                               7
                                 14                            21                    30                       47
                       10
                                  7 A data structure that can support fast5 order-statistic operations is
                                          16        19
                                                               4
                                                                      21       28                38
                                                                                                                 1

                       4        ure 14.1. An order-statistic tree T is simply a 3red-black tree with ad
                                           2         2                 1        1
                   7        12        14                    20    key                        35     39
                   2         1 mation stored in each node. Besides the usual red-black tree fields key
                                       1                     1                                1      1
               3                                                  size
               1                p[x], left[x], and right[x] in a node x, we have another field size[x]. T
                                tains the number of (internal) nodes in the subtree rooted at x (inclu
                            Figure 14.1 An order-statistic the which is an augmented red-blackthe sentinel’s are red,to be 0,
                                that is, the size of tree, subtree. If we define tree. Shaded nodes size
                            and darkened nodes ]] to beIn addition towe have the identity a field size[x], which is
                                size[nil[T are black. 0, then its usual fields, each node x has
                            the number of nodes in the subtree rooted at x.

                                size[x] = size[left[x]] + size[right[x]] + 1 .
                               A data structure that can support fast order-statistic operations is shown in Fig-
                            ure 14.1. An order-statistic tree T is to be distinct in anwith additional infor-
                                    We do not require keys simply a red-black tree order-statistic tree. (For
                            mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
                            p[x], left[x],Figure 14.1 has twowe havewith value size[x]. This field con-with val
                                tree in and right[x] in a node x, keys another field 14 and two keys
                            tains the number ofequal keys, the the subtree rooted of xrank is not itself), defined
                                presence of (internal) nodes in above notion at (including x well
                            thatthis ambiguity for an order-statistic tree by defining the we set of an e
                                 is, the size of the subtree. If we define the sentinel’s size to be 0, that is, rank
                            size[nil[T ]] to be 0, then we have the identity
                                position at which it would be printed in an inorder walk of the tree. I
               O(n)              O(lgn)
                            size[x] = size[left[x]] + size[right[x]] + 1 .in a black node has rank 5, and the ke
                                for example, the key 14 stored
2011   7   8
                               Werednot require keys to be distinct in an order-statistic tree. (For example, the
                                a do node has rank 6.
i

                           17
                                14.1 Dynamic order statistics                                                                     303
                                                                                      17
                                                                                      26
                                                                                      20
                                                    17                                                            41
                                                     12                                                            7
                                     14                               21                           30                            47
                                      7                               4                            5                              1
                           10                  16         19                     21        28                38
                           4                    2         2                       1        1                 3
                       7        12        14                     20        key                          35        39
                       2         1         1                      1                                     1          1
                   3                                                       size
                   1




                                Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                                and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                the number of nodes in the subtree rooted at x.


                                  A data structure that can support fast order-statistic operations is shown in Fig-
                                ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                    mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
i

                            17
                                 14.1 Dynamic order statistics                                                                     303

                   12                                                                  17
                                                                                       26
                                                     4                                 20
                                                         17                                                        41
                                                         12                                                         7
                                      14                               21                           30                            47
                                       7                                4                           5                              1
                            10                  16            19                  21        28                38
                            4                    2            2                    1        1                 3
                        7        12        14                      20       key                          35        39
                        2         1         1                      1                                     1          1
                   3                                                        size
                   1




                                 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                                 and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                 the number of nodes in the subtree rooted at x.


                                   A data structure that can support fast order-statistic operations is shown in Fig-
                                 ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                     mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
i

                            17
                                 14.1 Dynamic order statistics                                                                     303

                   12                                                                  17                      4
                                                     4
                                                                                       26
                                                                                       20
                                                                                                                   4
                                                         17                                                        41
                                                         12                                                         7
                                      14                               21                           30                            47
                                       7                                4                           5                              1
                            10                  16            19                  21        28                38
                            4                    2            2                    1        1                 3
                        7        12        14                      20       key                          35        39
                        2         1         1                      1                                     1          1
                   3                                                        size
                   1




                                 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                                 and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                 the number of nodes in the subtree rooted at x.


                                   A data structure that can support fast order-statistic operations is shown in Fig-
                                 ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                     mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
i

                            17
                                 14.1 Dynamic order statistics                                                                     303

                   12                                                                  17                      4
                                                     4
                                                                                       26
                                                                                       20
                                                                                                                   4
                                                         17                                                        41
                                                         12                                                         7
                                      14                               21                           30                            47
                                       7                                4                           5                              1
                            10                  16            19                  21        28                38
                            4                    2            2                    1        1                 3
                        7        12        14                      20       key                          35        39
                        2         1         1                      1                                     1          1
                   3                                                        size
                   1




                                 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                                 and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                 the number of nodes in the subtree rooted at x.


                                   A data structure that can support fast order-statistic operations is shown in Fig-
                                 ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                     mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
i

                            17
                                 14.1 Dynamic order statistics                                                                     303

                   12                                                                  17                      4
                                                     4
                                                                                       26
                                                                                       20
                                                                                                                    4
                                                         17                                        4                41
                                                         12                                                         7
                                      14                               21                           30                            47
                                       7                                4                             5                            1
                            10                  16            19                  21        28                 38
                            4                    2            2                    1        1                  3
                        7        12        14                      20       key                           35        39
                        2         1         1                      1                                      1         1
                   3                                                        size
                   1
                                                                                                  4

                                 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                                 and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                 the number of nodes in the subtree rooted at x.


                                   A data structure that can support fast order-statistic operations is shown in Fig-
                                 ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                     mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
i

                            17
                                 14.1 Dynamic order statistics                                                                     303

                   12                                                                  17                      4
                                                     4
                                                                                       26
                                                                                       20
                                                                                                                    4
                                                         17                                        4                41
                                                         12                                                         7
                                      14
                                       7
                                                                       21
                                                                        4
                                                                                                    30
                                                                                                      5
                                                                                                               2                  47
                                                                                                                                   1
                            10                  16            19                  21        28                 38
                            4                    2            2                    1        1                  3
                        7        12        14                      20       key                           35        39
                        2         1         1                      1                                      1         1
                   3                                                        size
                   1
                                                                                                  4

                                 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                                 and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                 the number of nodes in the subtree rooted at x.


                                   A data structure that can support fast order-statistic operations is shown in Fig-
                                 ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                     mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
i

                            17
                                 14.1 Dynamic order statistics                                                                     303

                   12                                                                  17                      4
                                                     4
                                                                                       26
                                                                                       20
                                                                                                                    4
                                                         17                                        4                41
                                                         12                                                         7
                                      14
                                       7
                                                                       21
                                                                        4
                                                                                                    30
                                                                                                      5
                                                                                                               2                  47
                                                                                                                                   1
                            10                  16            19                  21        28                 38
                            4                    2            2                    1        1                  3
                        7        12        14                      20       key                           35        39
                        2         1         1                      1                                      1         1
                   3                                                        size
                   1
                                                                                                  4

                                 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                                 and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                 the number of nodes in the subtree rooted at x.


                                   A data structure that can support fast order-statistic operations is shown in Fig-
                                 ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                     mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
14.1 Dynamic order statistics                                                                     303

                   12                                                                  17
                                                     4
                                                                                       26
                                                                                       20
                                                                                                                   4
                                                         17                                        4               41
                                                         12                                                         7
                                      14
                                       7
                                                                     21
                                                                        4
                                                                                                    30
                                                                                                    5
                                                                                                              2                   47
                                                                                                                                   1
                            10                  16            19                  21        28                38
                            4                    2            2                   1         1                 3
                        7        12        14                      20       key                          35        39
               Chapter 14 Augmenting Data Structures
                   2    1   1         1
                                          size
                                                                                                         1          1
                   3
                   1                                                                              4

                                 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
               OS-S ELECT (x, i) and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                                 the number of nodes in the subtree rooted at x.
               1 r ← size[left[x]]+1support fast order-statistic operations is shown in Fig-
                          A data structure that can
               2 if i = r An order-statistic tree T is simply a red-black tree with additional infor-
                       ure 14.1.
                       mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
               3     thenleft[x], and right[x] in a node x, we have another field size[x]. This field con-
                       p[x], return x
                       tains the number of (internal) nodes in the subtree rooted at x (including x itself),
               4 elseif iis,< size of the subtree. If we define the sentinel’s size to be 0, that is, we set
                       that the r
                       size[nil[T ]] to be 0, then we have the identity
               5     then return OS-S ELECT (left[x], i)
                       size[x] = size[left[x]] + size[right[x]] + 1 .
               6 else return require keysELECT (right[x], i tree. (For example, the
                          We do not
                                       OS-S to be distinct in an order-statistic − r)
2011   7   8
:38
                             14.1 Dynamic order statistics                                                                     303


                                                                                   26
                                                                                   20
                                                 17                                                            41
                                                  12                                                            7
                                  14                               21                           30                            47
                                   7                               4                            5                              1
                        10                  16         19                     21        28                38
                         4                   2         2                       1        1                 3
                    7        12        14                     20        key                          35        39
                    2         1         1                      1                                     1          1
               3                                                        size
               1




                             Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                             and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                             the number of nodes in the subtree rooted at x.


                               A data structure that can support fast order-statistic operations is shown in Fig-
                             ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
:38
                             14.1 Dynamic order statistics                                                                     303


                                                                                   26
                                                                                   20
                                                 17                                                            41
                                                  12                                                            7
                                  14
                                   7
                                                                   21
                                                                   4
                                                                                                30
                                                                                                5
                                                                                                          2                   47
                                                                                                                               1
                        10                  16         19                     21        28                38
                         4                   2         2                       1        1                 3
                    7        12        14                     20        key                          35        39
                    2         1         1                      1                                     1          1
               3                                                        size
               1




                             Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                             and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                             the number of nodes in the subtree rooted at x.


                               A data structure that can support fast order-statistic operations is shown in Fig-
                             ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
:38
                             14.1 Dynamic order statistics                                                                     303


                                                                                   26
                                                                                   20
                                                 17                                                            41
                                                  12                                                            7
                                  14
                                   7
                                                                   21
                                                                   4
                                                                                                30
                                                                                                5
                                                                                                          2                   47
                                                                                                                               1
                        10                  16         19                     21        28                38
                         4                   2         2                       1        1                 3
                    7        12        14                     20        key                          35        39
                    2         1         1                      1                                     1          1
               3                                                        size
               1




                             Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                             and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                             the number of nodes in the subtree rooted at x.


                               A data structure that can support fast order-statistic operations is shown in Fig-
                             ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
:38
                             14.1 Dynamic order statistics                                                                     303


                                                                                   26
                                                                                   20
                                                 17                                            4               41
                                                  12                                                            7
                                  14
                                   7
                                                                   21
                                                                   4
                                                                                                30
                                                                                                5
                                                                                                          2                   47
                                                                                                                               1
                        10                  16         19                     21        28                38
                         4                   2         2                       1        1                 3
                    7        12        14                     20        key                          35        39
                    2         1         1                      1                                     1          1
               3                                                        size
               1




                             Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                             and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                             the number of nodes in the subtree rooted at x.


                               A data structure that can support fast order-statistic operations is shown in Fig-
                             ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
:38
                             14.1 Dynamic order statistics                                                                     303
                                                                                                                    =
                                                                                   26
                                                                                   20
                                                                                                               4
                                                 17                                            4               41
                                                  12                                                            7
                                  14
                                   7
                                                                   21
                                                                   4
                                                                                                30
                                                                                                5
                                                                                                          2                   47
                                                                                                                               1
                        10                  16         19                     21        28                38
                         4                   2         2                       1        1                 3
                    7        12        14                     20        key                          35        39
                    2         1         1                      1                                     1          1
               3                                                        size
               1




                             Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                             and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                             the number of nodes in the subtree rooted at x.


                               A data structure that can support fast order-statistic operations is shown in Fig-
                             ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
:38
                             14.1 Dynamic order statistics                                                                     303
                                                                                   17                               =
                                                                                   26
                                                                                   20
                                                                                                               4
                                                 17                                            4               41
                                                  12                                                            7
                                  14
                                   7
                                                                   21
                                                                   4
                                                                                                30
                                                                                                5
                                                                                                          2                   47
                                                                                                                               1
                        10                  16         19                     21        28                38
                         4                   2         2                       1        1                 3
                    7        12        14                     20        key                          35        39
                    2         1         1                      1                                     1          1
               3                                                        size
               1




                             Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                             and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                             the number of nodes in the subtree rooted at x.


                               A data structure that can support fast order-statistic operations is shown in Fig-
                             ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
:38
                             14.1 Dynamic order statistics                                                                     303
                                                                                   17                               =
                                                                                   26
                                                                                   20
                                                                                                               4
                                                 17                                            4               41
                                                  12                                                            7
                                  14
                                   7
                                                                   21
                                                                   4
                                                                                                30
                                                                                                5
                                                                                                          2                   47
                                                                                                                               1
                        10                  16         19                     21        28                38
                         4                   2         2                       1        1                 3
                    7        12        14                     20        key                          35        39
                    2         1         1                      1                                     1          1
               3                                                        size
               1




                             Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                             and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
                             the number of nodes in the subtree rooted at x.


                               A data structure that can support fast order-statistic operations is shown in Fig-
                             ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
2011   7   8                 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
14.1 Dynamic order statistics                                                                 303
                                                                                  17                             =
                                                                                  26
                                                                                  20
                                                                                                             4
                                                  17                                         4               41
                                                  12                                                         7
                                   14
                                   7
                                                                  21
                                                                   4
                                                                                              30
                                                                                              5
                                                                                                        2                  47
                                                                                                                            1
                         10                  16        19                    21        28               38
                         4                   2         2                      1        1                3
                     7        12        14                    20       key                         35        39
                     2         1        1                     1                                    1         1
                 3                                                     size
                 1
               14.1 Dynamic order statistics

                          Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red,
                          and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is
               OS-R      (T, x)
                         ANKnumber of nodes in the subtree rooted at x.
                          the

               1 r ← size[left[x]] that 1 support fast order-statistic operations is shown in Fig-
                        A data structure + can
               2 y ←ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor-
                       x
                     mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
               3 while y = root[T ] in a node x, we have another field size[x]. This field con-
                      p[x], left[x], and right[x]
               4     do if y = right[ p[y]] in the subtree rooted at x (including x itself),
                     tains the number of (internal) nodes
                     that is, the size of the subtree. If we define the sentinel’s size to be 0, that is, we set
               5               then r then we have the identity
                     size[nil[T ]] to be 0,← r + size[left[ p[y]]] + 1
               6           y ← p[y]
                     size[x] = size[left[x]] + size[right[x]] + 1 .
               7 returnWe do not require keys to be distinct in an order-statistic tree. (For example, the
                          r
2011   7   8
naught. We shall now show that subtree sizes can be maintained
                        and deletion without affecting the asymptotic running time of eit
                            We noted in Section 13.3 that insertion into a red-black tre
                        phases. The first phase goes down the tree from the root, inser
                        as a child of an existing node. The second phase  ( goes up the tree
                 )      and ultimately performing rotations to maintain the red-black pr
                            To maintain the subtree sizes in the first phase, we simply inc
           Chapter 14 Augmenting Data Structures traversed from the root down toward th
                        each node x on the path
                        node added gets a size of 1. Since there are O(lg n) nodes on t
                        the additional cost of maintaining the size fields is O(lg n).
                                          LEFT-ROTATE(T, x)
                     42 In the second phase, the only structural changes to the underly
                                                                             93
                     19
                          x                                                  19
                                                                                y
                        are caused by rotations, of which there are at most two. Moreo
                               93                                   42
                                  y                                      x
                        local operation: RIGHT-ROTATE(T, y) have their size fields invalidated
                               12         only two nodes             11
            6                                                                         7
                        which the rotation is performed is incident on these two nodes
                        code for L7EFT-ROTATE (T, x) in Section 13.2,4 we add the follow
                            4                                    6


                         13 size[y] ← size[x]
           Figure 14.2   14 size[x] ← size[left[x]] + size[right[x]] + which the rotation is
                         Updating subtree sizes during rotations. The link around 1
           formed is incident on the two nodes whose size fields need to be updated. The updates are lo
           requiring only the size information stored in x, y, and the roots of the subtrees shown as triangle
                                                                        O(1)
                         Figure 14.2 illustrates how the fields are updated. The change t
2011   7   8             is symmetric.
14
               14.1              O(n)




                           (i   ) O(lgn)


               14.2

                    14.1


               14.3




2011   7   8
2011   7   8
size   (   )




               size



                          /
2011   7   8
14
               14.1              O(n)




                           (i   ) O(lgn)


               14.2

                    14.1


               14.3




2011   7   8
Chapter 14 Augmenting Data Structures


                           i                     i                       i                        i
                           i′                    i′                      i′                       i′


                                                            (a)


                       i                  i′                                     i′                i


                                 (b)                                                    (c)


               Figure 14.3 The interval trichotomy for two closed intervals i and i . (a) If i and i overlap, there
               are four situations; in each, low[i] ≤ high[i ] and low[i ] ≤ high[i]. (b) The intervals do not overlap,
               and high[i] < low[i ]. (c) The intervals do not overlap, and high[i ] < low[i].

2011   7   8
16                  21
                                                                        15                          23
                                                      8       9
                                                  6               10
                                              5           8
                              0         3
                                 0            5               10          15             20               25        30
                                                                          (a)                  (               ) int[x]

                                                                        [16,21]
                                                                          30

                                                                                                                    int
                                            [8,9]                                                       [25,30]
                                              23                                                          30        max

                           [5,8]                              [15,23]             [17,19]                           [26,26]
                            10                                     23               20                                    26


                [0,3]                [6,10]                                                   [19,20]
                  3                    10                                                          20
                                                                          (b)


               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
               (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted
               order by left endpoint.


               Step 3: Maintaining the information
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8
16                  21
                                                                        15                          23
                                                      8       9
                                                  6               10
                                              5           8
                              0         3
                                 0            5               10          15             20               25        30
                                                                          (a)                  (               ) int[x]

                                                                        [16,21]
                                                                          30

                                                                                                                    int
                                            [8,9]                                                       [25,30]
                                              23                                                          30        max

                           [5,8]                              [15,23]             [17,19]                           [26,26]
                            10                                     23               20                                    26


                [0,3]                [6,10]                                                   [19,20]
                  3                    10                                                          20
                                                                          (b)


               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
               (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted
               order by left endpoint.


               Step 3: Maintaining the information
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8
16                  21
                                                                        15                          23
                                                      8       9
                                                  6               10
                                              5           8
                              0         3
                                 0            5               10          15             20               25        30
                                                                          (a)                  (               ) int[x]

                                                                        [16,21]
                                                                          30

                                                                                                                    int
                                            [8,9]                                                       [25,30]
                                              23                                                          30        max

                           [5,8]                              [15,23]             [17,19]                           [26,26]
                            10                                     23               20                                    26


                [0,3]                [6,10]                                                   [19,20]
                  3                    10                                                          20
                                                                          (b)


               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
               (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted
               order by left endpoint.


               Step 3: Maintaining the information
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8
16                  21
                                                                        15                          23
                                                      8       9
                                                  6               10
                                              5           8
                              0         3
                                 0            5               10          15             20               25        30
                                                                          (a)                  (               ) int[x]

                                                                        [16,21]
                                                                          30

                                                                                                                    int
                                            [8,9]                                                       [25,30]
                                              23                                                          30        max

                           [5,8]                              [15,23]             [17,19]                           [26,26]
                            10                                     23               20                                    26


                [0,3]                [6,10]                                                   [19,20]
                  3                    10                                                          20
                                                                          (b)


               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
               (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted
               order by left endpoint.


               Step 3: Maintaining the information
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8
O(lgn)



               14.1            14.2-4 14.3-1




2011   7   8
19     20
                                                                              17        19
                                                                        16                   21
                                                                      15                           23
                                                     8       9
                                                 6               10
                                            5            8
                              0         3
                               0             5               10         15              20               25      30
                                                                        (a)

                                                                                    :          [22 25]
                                                                      [16,21]
  314             Chapter 14 Augmenting Data Structures
                                                      30

                                                                                                                 int
                                            [8,9]                                                      [25,30]
                  Step 4: Developing new operations
                                  23                                                                     30      max


                 The only new operation we need is I NTERVAL -S EARCH (T,[26,26]
                         [5,8]                [15,23]        [17,19]             i), which finds a node
                          10                    23              20                26
                 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in
                [0,3] tree, a pointer to the sentinel nil[T ] is returned.
                 the            [6,10]                               [19,20]
                  3                   10                                                          20
                                                                        (b)
                  I NTERVAL -S EARCH (T, i)
                  1 x ← root[T ]
               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
                   The while x that represents them. does not overlap int[x]
               (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted
                               do if
               order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i]
                  3
                  4                    then x ← left[x]
               Step 3: Maintaining the information
                  5                    else x ← right[x]
                  6 return x
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8   max values of node x’s children: that overlaps i starts with x at the root
                  The search for an interval                                                                           of the tree and
19      20
                                                                              17         19
                                                                        16                    21
                                                                      15                            23
                                                     8       9
                                                 6               10
                                            5            8
                              0         3
                               0             5               10         15               20               25      30
                                                                        (a)

                                                                                     :          [22 25]
                                                                                   [22 25]
                                                                      [16,21]
  314             Chapter 14 Augmenting Data Structures
                                                      30

                                                                                                                  int
                                            [8,9]                                                       [25,30]
                  Step 4: Developing new operations
                                  23                                                                      30      max


                 The only new operation we need is I NTERVAL -S EARCH (T,[26,26]
                         [5,8]                [15,23]        [17,19]             i), which finds a node
                          10                    23              20                26
                 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in
                [0,3] tree, a pointer to the sentinel nil[T ] is returned.
                 the            [6,10]                               [19,20]
                  3                   10                                                           20
                                                                        (b)
                  I NTERVAL -S EARCH (T, i)
                  1 x ← root[T ]
               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
                   The while x that represents them. does not overlap int[x]
               (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted
                               do if
               order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i]
                  3
                  4                    then x ← left[x]
               Step 3: Maintaining the information
                  5                    else x ← right[x]
                  6 return x
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8   max values of node x’s children: that overlaps i starts with x at the root
                  The search for an interval                                                                            of the tree and
19      20
                                                                              17         19
                                                                        16                    21
                                                                      15                            23
                                                     8       9
                                                 6               10
                                            5            8
                              0         3
                               0             5               10         15               20               25      30
                                                                        (a)

                                                                                     :          [22 25]
                                                                                   [22 25]
                                                                      [16,21]
  314             Chapter 14 Augmenting Data Structures
                                                      30

                                                     [22 25]                                                      int
                                            [8,9]                                                       [25,30]
                  Step 4: Developing new operations
                                  23                                                                      30      max


                 The only new operation we need is I NTERVAL -S EARCH (T,[26,26]
                         [5,8]                [15,23]        [17,19]             i), which finds a node
                          10                    23              20                26
                 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in
                [0,3] tree, a pointer to the sentinel nil[T ] is returned.
                 the            [6,10]                               [19,20]
                  3                   10                                                           20
                                                                        (b)
                  I NTERVAL -S EARCH (T, i)
                  1 x ← root[T ]
               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
                   The while x that represents them. does not overlap int[x]
               (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted
                               do if
               order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i]
                  3
                  4                    then x ← left[x]
               Step 3: Maintaining the information
                  5                    else x ← right[x]
                  6 return x
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8   max values of node x’s children: that overlaps i starts with x at the root
                  The search for an interval                                                                            of the tree and
19      20
                                                                              17         19
                                                                        16                    21
                                                                      15                            23
                                                     8       9
                                                 6               10
                                            5            8
                              0         3
                               0             5               10         15               20               25      30
                                                                        (a)

                                                                                     :          [22 25]
                                                                                   [22 25]
                                                                      [16,21]
  314             Chapter 14 Augmenting Data Structures
                                                      30

                                                     [22 25]                                                      int
                                            [8,9]                                                       [25,30]
                  Step 4: Developing new operations
                                  23                                                                      30      max


                 The only new operation we need is I NTERVAL -S EARCH (T,[26,26]
                         [5,8]                [15,23]        [17,19]             i), which finds a node
                          10                    23              20                26
                 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in
                [0,3] tree, a pointer to the sentinel nil[T ] is returned.
                 the            [6,10]                               [19,20]
                  3                   10                                                           20
                                                                        (b)
                  I NTERVAL -S EARCH (T, i)
                  1 x ← root[T ]
               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
                   The while x that represents them. does not overlap int[x]
               (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted
                               do if
               order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i]
                  3
                  4                    then x ← left[x]
               Step 3: Maintaining the information
                  5                    else x ← right[x]
                  6 return x
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8   max values of node x’s children: that overlaps i starts with x at the root
                  The search for an interval                                                                            of the tree and
19      20
                                                                               17         19
                                                                          16                   21
                                                                        15                           23
                                                     8       9
                                                 6               10
                                            5            8
                              0         3
                               0             5               10          15               20               25      30
                                                                         (a)

                                                                                      :          [22 25]
                                                                                    [22 25]
                                                                       [16,21]
  314             Chapter 14 Augmenting Data Structures
                                                      30

                                                     [22 25]                                                       int
                                            [8,9]                                                        [25,30]
                  Step 4: Developing new operations
                                  23                                                                       30      max
                                                                      [22 25]
                 The only new operation we need is I NTERVAL -S EARCH (T,[26,26]
                         [5,8]                [15,23]        [17,19]             i), which finds a node
                          10                    23              20                26
                 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in
                [0,3] tree, a pointer to the sentinel nil[T ] is returned.
                 the            [6,10]                               [19,20]
                  3                   10                                                            20
                                                                         (b)
                  I NTERVAL -S EARCH (T, i)
                  1 x ← root[T ]
               Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint.
                   The while x that represents them. does not overlap int[x]
               (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted
                               do if
               order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i]
                  3
                  4                    then x ← left[x]
               Step 3: Maintaining the information
                  5                    else x ← right[x]
                  6 return x
               We must verify that insertion and deletion can be performed in O(lg n) time on an
               interval tree of n nodes. We can determine max[x] given interval int[x] and the
2011   7   8   max values of node x’s children: that overlaps i starts with x at the root
                  The search for an interval                                                                             of the tree and
b




2011   7   8
Thank you




2011   7   8
Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to
               (b) The interval tree that represents them. An inorder tree walk of the tree list
               order by left endpoint.


               Step 3: Maintaining the information
               We must verify that insertion and deletion can be performed in O
                              O(lgn)
               interval tree of n nodes. We can determine max[x] given interv
               max values of node x’s children:
               max[x] = max(high[int[x]], max[left[x]], max[right[x]]) .
               Thus, by Theorem 14.1, insertion and deletion run in O(lg n) tim
               ing the max fields after a rotation can be accomplished in O(1)
               in Exercises 14.2-4 and 14.3-1.




2011   7   8

More Related Content

Recently uploaded

Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
FilipTomaszewski5
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
Fwdays
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
DianaGray10
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
AlexanderRichford
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
Sease
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 

Recently uploaded (20)

Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

アルゴリズムイントロダクション 14章

  • 1. 14 2011 7 8
  • 2. OK (^^)b 2011 7 8
  • 3. 14 14.1 O(n) (i ) O(lgn) 14.2 14.1 14.3 2011 7 8
  • 4. 3 size 1 14.1 Dynamic order statistics 303 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shade and darkened nodes are black. In addition to its usual fields, each node x has a field 26 the number of nodes in the subtree rooted at x. 20 17 41 12 7 14 21 30 47 10 7 A data structure that can support fast5 order-statistic operations is 16 19 4 21 28 38 1 4 ure 14.1. An order-statistic tree T is simply a 3red-black tree with ad 2 2 1 1 7 12 14 20 key 35 39 2 1 mation stored in each node. Besides the usual red-black tree fields key 1 1 1 1 3 size 1 p[x], left[x], and right[x] in a node x, we have another field size[x]. T tains the number of (internal) nodes in the subtree rooted at x (inclu Figure 14.1 An order-statistic the which is an augmented red-blackthe sentinel’s are red,to be 0, that is, the size of tree, subtree. If we define tree. Shaded nodes size and darkened nodes ]] to beIn addition towe have the identity a field size[x], which is size[nil[T are black. 0, then its usual fields, each node x has the number of nodes in the subtree rooted at x. size[x] = size[left[x]] + size[right[x]] + 1 . A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is to be distinct in anwith additional infor- We do not require keys simply a red-black tree order-statistic tree. (For mation stored in each node. Besides the usual red-black tree fields key[x], color[x], p[x], left[x],Figure 14.1 has twowe havewith value size[x]. This field con-with val tree in and right[x] in a node x, keys another field 14 and two keys tains the number ofequal keys, the the subtree rooted of xrank is not itself), defined presence of (internal) nodes in above notion at (including x well thatthis ambiguity for an order-statistic tree by defining the we set of an e is, the size of the subtree. If we define the sentinel’s size to be 0, that is, rank size[nil[T ]] to be 0, then we have the identity position at which it would be printed in an inorder walk of the tree. I O(n) O(lgn) size[x] = size[left[x]] + size[right[x]] + 1 .in a black node has rank 5, and the ke for example, the key 14 stored 2011 7 8 Werednot require keys to be distinct in an order-statistic tree. (For example, the a do node has rank 6.
  • 5. i 17 14.1 Dynamic order statistics 303 17 26 20 17 41 12 7 14 21 30 47 7 4 5 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 6. i 17 14.1 Dynamic order statistics 303 12 17 26 4 20 17 41 12 7 14 21 30 47 7 4 5 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 7. i 17 14.1 Dynamic order statistics 303 12 17 4 4 26 20 4 17 41 12 7 14 21 30 47 7 4 5 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 8. i 17 14.1 Dynamic order statistics 303 12 17 4 4 26 20 4 17 41 12 7 14 21 30 47 7 4 5 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 9. i 17 14.1 Dynamic order statistics 303 12 17 4 4 26 20 4 17 4 41 12 7 14 21 30 47 7 4 5 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 4 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 10. i 17 14.1 Dynamic order statistics 303 12 17 4 4 26 20 4 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 4 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 11. i 17 14.1 Dynamic order statistics 303 12 17 4 4 26 20 4 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 4 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 12. 14.1 Dynamic order statistics 303 12 17 4 26 20 4 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 Chapter 14 Augmenting Data Structures 2 1 1 1 size 1 1 3 1 4 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, OS-S ELECT (x, i) and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. 1 r ← size[left[x]]+1support fast order-statistic operations is shown in Fig- A data structure that can 2 if i = r An order-statistic tree T is simply a red-black tree with additional infor- ure 14.1. mation stored in each node. Besides the usual red-black tree fields key[x], color[x], 3 thenleft[x], and right[x] in a node x, we have another field size[x]. This field con- p[x], return x tains the number of (internal) nodes in the subtree rooted at x (including x itself), 4 elseif iis,< size of the subtree. If we define the sentinel’s size to be 0, that is, we set that the r size[nil[T ]] to be 0, then we have the identity 5 then return OS-S ELECT (left[x], i) size[x] = size[left[x]] + size[right[x]] + 1 . 6 else return require keysELECT (right[x], i tree. (For example, the We do not OS-S to be distinct in an order-statistic − r) 2011 7 8
  • 13. :38 14.1 Dynamic order statistics 303 26 20 17 41 12 7 14 21 30 47 7 4 5 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 14. :38 14.1 Dynamic order statistics 303 26 20 17 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 15. :38 14.1 Dynamic order statistics 303 26 20 17 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 16. :38 14.1 Dynamic order statistics 303 26 20 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 17. :38 14.1 Dynamic order statistics 303 = 26 20 4 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 18. :38 14.1 Dynamic order statistics 303 17 = 26 20 4 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 19. :38 14.1 Dynamic order statistics 303 17 = 26 20 4 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is the number of nodes in the subtree rooted at x. A data structure that can support fast order-statistic operations is shown in Fig- ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- 2011 7 8 mation stored in each node. Besides the usual red-black tree fields key[x], color[x],
  • 20. 14.1 Dynamic order statistics 303 17 = 26 20 4 17 4 41 12 7 14 7 21 4 30 5 2 47 1 10 16 19 21 28 38 4 2 2 1 1 3 7 12 14 20 key 35 39 2 1 1 1 1 1 3 size 1 14.1 Dynamic order statistics Figure 14.1 An order-statistic tree, which is an augmented red-black tree. Shaded nodes are red, and darkened nodes are black. In addition to its usual fields, each node x has a field size[x], which is OS-R (T, x) ANKnumber of nodes in the subtree rooted at x. the 1 r ← size[left[x]] that 1 support fast order-statistic operations is shown in Fig- A data structure + can 2 y ←ure 14.1. An order-statistic tree T is simply a red-black tree with additional infor- x mation stored in each node. Besides the usual red-black tree fields key[x], color[x], 3 while y = root[T ] in a node x, we have another field size[x]. This field con- p[x], left[x], and right[x] 4 do if y = right[ p[y]] in the subtree rooted at x (including x itself), tains the number of (internal) nodes that is, the size of the subtree. If we define the sentinel’s size to be 0, that is, we set 5 then r then we have the identity size[nil[T ]] to be 0,← r + size[left[ p[y]]] + 1 6 y ← p[y] size[x] = size[left[x]] + size[right[x]] + 1 . 7 returnWe do not require keys to be distinct in an order-statistic tree. (For example, the r 2011 7 8
  • 21. naught. We shall now show that subtree sizes can be maintained and deletion without affecting the asymptotic running time of eit We noted in Section 13.3 that insertion into a red-black tre phases. The first phase goes down the tree from the root, inser as a child of an existing node. The second phase ( goes up the tree ) and ultimately performing rotations to maintain the red-black pr To maintain the subtree sizes in the first phase, we simply inc Chapter 14 Augmenting Data Structures traversed from the root down toward th each node x on the path node added gets a size of 1. Since there are O(lg n) nodes on t the additional cost of maintaining the size fields is O(lg n). LEFT-ROTATE(T, x) 42 In the second phase, the only structural changes to the underly 93 19 x 19 y are caused by rotations, of which there are at most two. Moreo 93 42 y x local operation: RIGHT-ROTATE(T, y) have their size fields invalidated 12 only two nodes 11 6 7 which the rotation is performed is incident on these two nodes code for L7EFT-ROTATE (T, x) in Section 13.2,4 we add the follow 4 6 13 size[y] ← size[x] Figure 14.2 14 size[x] ← size[left[x]] + size[right[x]] + which the rotation is Updating subtree sizes during rotations. The link around 1 formed is incident on the two nodes whose size fields need to be updated. The updates are lo requiring only the size information stored in x, y, and the roots of the subtrees shown as triangle O(1) Figure 14.2 illustrates how the fields are updated. The change t 2011 7 8 is symmetric.
  • 22. 14 14.1 O(n) (i ) O(lgn) 14.2 14.1 14.3 2011 7 8
  • 23. 2011 7 8
  • 24. size ( ) size / 2011 7 8
  • 25. 14 14.1 O(n) (i ) O(lgn) 14.2 14.1 14.3 2011 7 8
  • 26. Chapter 14 Augmenting Data Structures i i i i i′ i′ i′ i′ (a) i i′ i′ i (b) (c) Figure 14.3 The interval trichotomy for two closed intervals i and i . (a) If i and i overlap, there are four situations; in each, low[i] ≤ high[i ] and low[i ] ≤ high[i]. (b) The intervals do not overlap, and high[i] < low[i ]. (c) The intervals do not overlap, and high[i ] < low[i]. 2011 7 8
  • 27. 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) ( ) int[x] [16,21] 30 int [8,9] [25,30] 23 30 max [5,8] [15,23] [17,19] [26,26] 10 23 20 26 [0,3] [6,10] [19,20] 3 10 20 (b) Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted order by left endpoint. Step 3: Maintaining the information We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8
  • 28. 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) ( ) int[x] [16,21] 30 int [8,9] [25,30] 23 30 max [5,8] [15,23] [17,19] [26,26] 10 23 20 26 [0,3] [6,10] [19,20] 3 10 20 (b) Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted order by left endpoint. Step 3: Maintaining the information We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8
  • 29. 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) ( ) int[x] [16,21] 30 int [8,9] [25,30] 23 30 max [5,8] [15,23] [17,19] [26,26] 10 23 20 26 [0,3] [6,10] [19,20] 3 10 20 (b) Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted order by left endpoint. Step 3: Maintaining the information We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8
  • 30. 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) ( ) int[x] [16,21] 30 int [8,9] [25,30] 23 30 max [5,8] [15,23] [17,19] [26,26] 10 23 20 26 [0,3] [6,10] [19,20] 3 10 20 (b) Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. (b) The interval tree that represents them. An inorder tree walk of the tree lists the nodes in sorted order by left endpoint. Step 3: Maintaining the information We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8
  • 31. O(lgn) 14.1 14.2-4 14.3-1 2011 7 8
  • 32. 19 20 17 19 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) : [22 25] [16,21] 314 Chapter 14 Augmenting Data Structures 30 int [8,9] [25,30] Step 4: Developing new operations 23 30 max The only new operation we need is I NTERVAL -S EARCH (T,[26,26] [5,8] [15,23] [17,19] i), which finds a node 10 23 20 26 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in [0,3] tree, a pointer to the sentinel nil[T ] is returned. the [6,10] [19,20] 3 10 20 (b) I NTERVAL -S EARCH (T, i) 1 x ← root[T ] Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. The while x that represents them. does not overlap int[x] (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted do if order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i] 3 4 then x ← left[x] Step 3: Maintaining the information 5 else x ← right[x] 6 return x We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8 max values of node x’s children: that overlaps i starts with x at the root The search for an interval of the tree and
  • 33. 19 20 17 19 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) : [22 25] [22 25] [16,21] 314 Chapter 14 Augmenting Data Structures 30 int [8,9] [25,30] Step 4: Developing new operations 23 30 max The only new operation we need is I NTERVAL -S EARCH (T,[26,26] [5,8] [15,23] [17,19] i), which finds a node 10 23 20 26 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in [0,3] tree, a pointer to the sentinel nil[T ] is returned. the [6,10] [19,20] 3 10 20 (b) I NTERVAL -S EARCH (T, i) 1 x ← root[T ] Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. The while x that represents them. does not overlap int[x] (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted do if order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i] 3 4 then x ← left[x] Step 3: Maintaining the information 5 else x ← right[x] 6 return x We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8 max values of node x’s children: that overlaps i starts with x at the root The search for an interval of the tree and
  • 34. 19 20 17 19 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) : [22 25] [22 25] [16,21] 314 Chapter 14 Augmenting Data Structures 30 [22 25] int [8,9] [25,30] Step 4: Developing new operations 23 30 max The only new operation we need is I NTERVAL -S EARCH (T,[26,26] [5,8] [15,23] [17,19] i), which finds a node 10 23 20 26 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in [0,3] tree, a pointer to the sentinel nil[T ] is returned. the [6,10] [19,20] 3 10 20 (b) I NTERVAL -S EARCH (T, i) 1 x ← root[T ] Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. The while x that represents them. does not overlap int[x] (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted do if order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i] 3 4 then x ← left[x] Step 3: Maintaining the information 5 else x ← right[x] 6 return x We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8 max values of node x’s children: that overlaps i starts with x at the root The search for an interval of the tree and
  • 35. 19 20 17 19 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) : [22 25] [22 25] [16,21] 314 Chapter 14 Augmenting Data Structures 30 [22 25] int [8,9] [25,30] Step 4: Developing new operations 23 30 max The only new operation we need is I NTERVAL -S EARCH (T,[26,26] [5,8] [15,23] [17,19] i), which finds a node 10 23 20 26 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in [0,3] tree, a pointer to the sentinel nil[T ] is returned. the [6,10] [19,20] 3 10 20 (b) I NTERVAL -S EARCH (T, i) 1 x ← root[T ] Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. The while x that represents them. does not overlap int[x] (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted do if order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i] 3 4 then x ← left[x] Step 3: Maintaining the information 5 else x ← right[x] 6 return x We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8 max values of node x’s children: that overlaps i starts with x at the root The search for an interval of the tree and
  • 36. 19 20 17 19 16 21 15 23 8 9 6 10 5 8 0 3 0 5 10 15 20 25 30 (a) : [22 25] [22 25] [16,21] 314 Chapter 14 Augmenting Data Structures 30 [22 25] int [8,9] [25,30] Step 4: Developing new operations 23 30 max [22 25] The only new operation we need is I NTERVAL -S EARCH (T,[26,26] [5,8] [15,23] [17,19] i), which finds a node 10 23 20 26 in tree T whose interval overlaps interval i. If there is no interval that overlaps i in [0,3] tree, a pointer to the sentinel nil[T ] is returned. the [6,10] [19,20] 3 10 20 (b) I NTERVAL -S EARCH (T, i) 1 x ← root[T ] Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to top by left endpoint. The while x that represents them. does not overlap int[x] (b)2 interval tree = nil[T ] and i An inorder tree walk of the tree lists the nodes in sorted do if order by left endpoint. left[x] = nil[T ] and max[left[x]] ≥ low[i] 3 4 then x ← left[x] Step 3: Maintaining the information 5 else x ← right[x] 6 return x We must verify that insertion and deletion can be performed in O(lg n) time on an interval tree of n nodes. We can determine max[x] given interval int[x] and the 2011 7 8 max values of node x’s children: that overlaps i starts with x at the root The search for an interval of the tree and
  • 37. b 2011 7 8
  • 39. Figure 14.4 An interval tree. (a) A set of 10 intervals, shown sorted bottom to (b) The interval tree that represents them. An inorder tree walk of the tree list order by left endpoint. Step 3: Maintaining the information We must verify that insertion and deletion can be performed in O O(lgn) interval tree of n nodes. We can determine max[x] given interv max values of node x’s children: max[x] = max(high[int[x]], max[left[x]], max[right[x]]) . Thus, by Theorem 14.1, insertion and deletion run in O(lg n) tim ing the max fields after a rotation can be accomplished in O(1) in Exercises 14.2-4 and 14.3-1. 2011 7 8