Questions tagged [patricia-trie]

Patricia trees are a term for a specialised kind of Radix tree. A radix tree is a space-optimized trie data structure where each node with only one child is merged with its child. This means every internal node has at least two children. Unlike in regular trees, edges can be labeled with sequences of characters as well as single characters. This makes them much more efficient for small sets and for sets of strings that share long prefixes.

According to the Wikipedia article on Radix trees

Donald R. Morrison first described what he called "Patricia trees" in 1968; the name comes from the acronym PATRICIA, which stands for "Practical Algorithm To Retrieve Information Coded In Alphanumeric". Gernot Gwehenberger independently invented and described the data structure at about the same time.


The formal specification for PATRICIA, located in the Journal of ACM Volume 15 Issue 4, Oct. 1968 Pages 514-534 specifies a group of algorithms that produce a tree with very specific requirements. Some examples of those requirements, taken from this document are as follows:

... it was decided that the alphabet should be restricted to a binary one. A theorem which strongly influenced this decision is one which, in another form, is due to Euler. The theorem states that if the alphabet is binary, then the number of branches is exactly one less than the number of ends. Corollaries state that as the library grows, each new end brings into the library with it exactly one new branch, and each branch has exactly two exits. These facts are very useful in the allocation of storage for the index. They imply that the total storage required is completely determined by the number of ends, and all of the storage required will actually be used.

In summary:

  • A PATRICIA data structure has the same structure as a binary tree.
  • There are no 'internal nodes'; "the total storage required is completely determined by the number of ends".
40 questions
130
votes
4 answers

What is the difference between trie and radix trie data structures?

Are the trie and radix trie data structures the same thing? If they aren't the same, then what is the meaning of radix trie (AKA Patricia trie)?
Aryak Sengupta
  • 1,727
  • 2
  • 18
  • 23
19
votes
1 answer

Is there some way to reduce the pain of range tracking?

There's currently a pull request by Jonathan S. to replace the implementation of Data.IntMap with one explained in this README based on ideas from a blog post by Edward Kmett. The basic concept Jonathan S. developed from is that an IntMap is a…
dfeuer
  • 48,079
  • 5
  • 63
  • 167
12
votes
2 answers

Are there any radix/patricia/critbit trees for Python?

I have about 10,000 words used as a set of inverted indices to about 500,000 documents. Both are normalized so the index is a mapping of integers (word id) to a set of integers (ids of documents which contain the word). My prototype uses Python's…
Andrew Dalke
  • 14,889
  • 4
  • 39
  • 54
11
votes
2 answers

Implementing a Patricia Trie for use as a dictionary

I'm attempting to implement a Patricia Trie with the methods addWord(), isWord(), and isPrefix() as a means to store a large dictionary of words for quick retrieval (including prefix search). I've read up on the concepts but they just aren't…
Regis Frey
  • 888
  • 1
  • 11
  • 21
8
votes
1 answer

STLish lower_bound function for Radix/Patricia Trie

Lately I've been studying Patricia tries, and working with a really good C++ implementation which can be used as an STL Sorted Associative Container. Patricia tries differ from normal binary trees because leaf nodes have back pointers which point…
Channel72
  • 283
  • 1
  • 2
  • 5
7
votes
3 answers

Algorithm/steps to find Longest Prefix search in Patricia Trie

I am implementing Patricia tries for IP prefix lookup, I could get the code working for complete key match, but facing problems with prefix search, when there are keys which are prefixes of other keys, like: 1.2.3.0 1.2.0.0 Can anyone help me with…
Ani
  • 1,448
  • 1
  • 16
  • 38
7
votes
1 answer

Significance of the term "Radix" in Radix Tree

While it is hard to find an unanimous definition of "Radix Tree", most accepted definitions of Radix Tree indicate that it is a compacted Prefix Tree. What I'm struggling to understand is the significance of the term "radix" in this case. Why…
KGhatak
  • 6,995
  • 1
  • 27
  • 24
6
votes
1 answer

Index Fabric (layered Patricia trie)

I'm currently trying to implement the Index Fabric for a dna sequence data search system: Index fabric algorithm I could implement the normal patricia trie, but I still couldn't understand how to add layers. I also tried google but couldn't find…
Nuwan
  • 177
  • 1
  • 3
  • 13
6
votes
1 answer

How to create, update and read a radix tree that won't fit into memory?

I’m interested in using a radix tree (or Patricia trie) to store a hash/dict/array of strings -> values. However, I'm finding that I have too many strings to fit into memory. I found an article by Algolia about how they solved this problem with…
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
6
votes
4 answers

what the author of nedtries means by "in-place"?

I. Just implemented a kind of bitwise trie (based on nedtries), but my code does lot Of memory allocation (for each node). Contrary to my implemetation, nedtries are claimed to be fast , among othet things, Because of their small number of memory…
fokenrute
  • 739
  • 6
  • 17
5
votes
4 answers

Prefix search in a radix tree/patricia trie

I'm currently implementing a radix tree/patricia trie (whatever you want to call it). I want to use it for prefix searches in a dictionary on a severely underpowered piece of hardware. It's supposed to work more or less like auto-completion, i. e.…
j66k
  • 53
  • 1
  • 1
  • 3
5
votes
1 answer

python implementation of patricia tries

Looking around for python implementations of tries just so that I can understand what they are and how they work, I came across Justin Peel's patricia trie and found it very instructive: it's straightforward enough for one as new as I am to play…
jjon
  • 680
  • 1
  • 8
  • 23
5
votes
2 answers

Determine if one string is a prefix of another

I have written down a simple function that determines if str1 is a prefix of str2. It's a very simple function, that looks like this (in JS): function isPrefix(str1, str2) // determine if str1 is a prefix of a candidate string { if(str2.length…
Parijat Kalia
  • 4,929
  • 10
  • 50
  • 77
4
votes
1 answer

How can I read this Radix Tree structure to determine next-string probability?

In JavaScript, I am attempting to take a given user input and guess the 3 most likely words that might complete the user's currently (incomplete) typed word. The guess is based on the user's past inputs. I'm working on this here, in this…
user2076675
3
votes
1 answer

Merkle Patricia Tree (Ethereum) and Hashtable, which one has faster search speed?

Goal: I would like to implement a function which has a sequence of inputs "X1,...,Xn" and outputs an ordered list "Xp,..,Xq" where all the elements are distinct but ordered. Requirement: For every Xi in the sequence "X1,...,Xn", it is a 256 bits…
1
2 3