17. Augmenting Data Structures
Exercises
17.1-1
Available in the latest revision of the IM.
17.1-2
Available in the latest revision of the IM.
17.1-3
Available in the latest revision of the IM.
OS-Select(x, i)
1 r = x.left.size + 1
2 while i != r
3 if i < r
4 x = x.left
5 else
6 x = x.right
7 i = i - r
8 r = x.left.size + 1
9 return x17.1-4
Available in the latest revision of the IM.
17.1-5
Available in the latest revision of the IM.
17.1-6
Available in the latest revision of the IM.
17.1-7
Available in the latest revision of the IM.
★ 17.1-8
Available in the latest revision of the IM.
17.2-1 🌟
Available in the latest revision of the IM.
17.2-2
Available in the latest revision of the IM.
17.2-3
Available in the latest revision of the IM.
17.3-1
Available in the latest revision of the IM.
17.3-2
Available in the latest revision of the IM.
17.3-3
The non-modifying version of the pseudocode follows the structure of the solution from the previous exercise. An ordinary inorder traversal of a tree would entail a runtime. Leveraging additional information stored in nodes we can make informed decisions whether to descend into branches. This reduces the running time as given in the book. There is only one caveat, that an unsuccessful search also consumes time, so for we don't have a zero time.
17.3-4
First, we must modify the tree's insertion procedure to use int.high as a secondary key.
If
i.low < x.int.low, go left.If
i.low > x.int.low, go right.If
i.low == x.int.low, comparei.highandx.int.highto decide whether to go left or right (see below).
With the above modification, an interval tree can be regarded as an ordinary BST for exact search.
17.3-5
Available in the latest revision of the IM.
★ 17.3-6
Available in the latest revision of the IM.
Problems
17-1 Point of maximum overlap
Available in the latest revision of the IM.
17-2 Josephus permutation
Available in the latest revision of the IM.
Last updated