Given two strings a = a 0 a 1 . . .a p and b = b

Question:

Given two strings a = a0a1 . . .ap and b = b0b1 . . .bq, where each ai and each bj is in some ordered set of characters, we say that string a is lexicographically less than string b if either 

1. there exists an integer j, where 0 ≤ j ≤ min(p, q), such that ai = bi for all i = 0, 1, . . . , j – 1 and aj < bj, or

2. p < q and ai = bi for all i = 0, 1, . . . , p.

For example, if a and b are bit strings, then 10100 < 10110 by rule 1 (letting j = 3) and 10100 < 101000 by rule 2. This ordering is similar to that used in English-language dictionaries.

The radix tree data structure shown in Figure 12.5 stores the bit strings 1011, 10, 011, 100, and 0. When searching for a key a = a0a1 . . .ap, we go left at a node of depth i if ai = 0 and right if ai = 1. Let S be a set of distinct bit strings whose lengths sum to n. Show how to use a radix tree to sort S lexicographically in Θ(n) time. For the example in Figure 12.5, the output of the sort should be the sequence 0, 011, 10, 100, 1011.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Introduction to Algorithms

ISBN: 978-0262033848

3rd edition

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

Question Posted: