For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

17.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 Θ(n)\Theta(n) 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 k=0k=0 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, compare i.high and x.int.high to decide whether to go left or right (see below).

Leaving the max attribute and the standard overlap logic completely untouched means all our existing operations—like regular interval search—work as before.

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.

The modular arithmetic to compute the next rank jj is as follows: j = (j + m - 1) mod k if j == 0 j = k The IM employs a neat trick to condense all this into a one-liner: j = ((j + m - 2) mod k) + 1. The idea is to first shift the whole domain down by subtracting -1. The modulo operator safely wraps the value within the range [0,k1][0, k-1]. Adding 1 shifts the result back to the desired [1,k][1, k] range.

Last updated