What does radix mean in a radix tree?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 19:20:34

As already mentioned by @ta in the Wikipedia etymology link, the 'radix', is the the base of your trie. In this case we mean the numeric base, and we'll consider storing binary data. Radix R = 2 ^ x, where x >= 1.

Take the example of a binary (2-ary) trie. The radix is 2, so at each node you can compare one bit. The two children will handle all of the possible outcomes:

  • the bit is 0
  • the bit is 1

The next level of complexity would be a 4-ary trie. As @Garrett mentioned above, the radix must be a power of two so that it can always handle all possible sorting outcomes of the binary data we're using it for. A 4-ary trie can compare two binary bits with the four possible outcomes:

  • 00
  • 01
  • 10
  • 10

These four options each lead to a different child node.

Now, in answer to your question about the radix for the English alphabet. You want to encode letters from a to z (26 letters) so will need to have a radix of at least 2^5 = 32. This is the smallest radix that will let you switch between every letter and conform to the 'powers of two' rule. 2^4 = 16 wouldn't handle all of the letters.

As an example, let's imagine the following encoding:

  • 00000 represents 'a',
  • 00001 represents 'b',
  • ... etc
  • 11001 represents 'z',
  • 11010 to 11111 are not in use (yet)

we can now do a comparison of five bits at every node in the tree, so every node can now switch between any Roman-alphabet letter. If you want a trie that will handle upper case letters then you will require a larger radix. A radix of 2^6 will give you enough to do this, but it comes at the cost of more wasted space (unused branches) in the trie.

Further reading: Sedgewick, Ch 15.4, on Multiway Tries. The 3rd edition of Algorithms by Cormen is generally excellent but doesn't do much for multiway tries.

Garrett Openshaw

There is some info on Wikipedia:

The result is that every internal node has up to the number of children of the radix r of the radix trie, where r is a positive integer and a power x of 2, having x ≥ 1.

So the radix signifies the number of children of each internal node, and that number must be a power of 2. When the radix is 2, we have a familiar binary tree.

KGhatak

I've posted an answer to this as a response to another thread - What is the difference between trie and radix trie data structures?. Specifically the sections Radix Trie and Trie that may not be a Radix Trie might be of special interest for this question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!