Radix trees Given two strings a D a0a1 :::ap and b D b0b1 | StudySoup

Textbook Solutions for Introduction to Algorithms

Chapter 12 Problem 12-2

Question

Radix trees Given two strings a D a0a1 :::ap and b D 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 D bi for all i D 0; 1; : : : ; j 1 and aj < bj , or 2. p< 10110 by rule 1 (letting j D 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 D a0a1 :::ap, we go left at a node of depth i if ai D 0 and right if ai D 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.

Solution

Step 1 of 7)

The first step in solving 12 problem number 2 trying to solve the problem we have to refer to the textbook question: Radix trees Given two strings a D a0a1 :::ap and b D 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 D bi for all i D 0; 1; : : : ; j 1 and aj &lt; bj , or 2. p&lt; 10110 by rule 1 (letting j D 3) and 10100 &lt; 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 D a0a1 :::ap, we go left at a node of depth i if ai D 0 and right if ai D 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.
From the textbook chapter Binary Search Trees you will find a few key concepts needed to solve this.

Step 2 of 7)

Visible to paid subscribers only

Step 3 of 7)

Visible to paid subscribers only

Subscribe to view the
full solution

Title Introduction to Algorithms 3 
Author Thomas H. Cormen
ISBN 9780262033848

Radix trees Given two strings a D a0a1 :::ap and b D b0b1

Chapter 12 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back