What is a Patricia tree, and how does it work?

A Patricia tree is a compressed trie data structure that stores strings for efficient retrieval and search operations.

The term Patricia stands for Practical Algorithm to Retrieve Information Coded in Alphanumeric, and it was introduced by Donald R. Morrison in 1968. The Patricia tree is a type of radix tree (or prefix tree) that compresses the paths in the trie that contain a single child node, thereby reducing the space complexity and improving the efficiency of operations.

In a Patricia tree, each node represents a string (or a part of a string), and each edge represents a binary digit that differentiates between the strings. The strings are stored in the leaf nodes, while the internal nodes contain indexes that point to the bit position in the strings that differentiates between them. This structure allows for efficient search, insertion, and deletion operations, as they can be performed in O(k) time, where k is the length of the string.

To understand how a Patricia tree works, let's consider an example. Suppose we want to store the words 'to', 'tea', 'ted', 'ten', 'A', 'i', and 'in'. We start by creating a root node with an empty string. Then, for each word, we traverse the tree from the root, following the path defined by the binary digits of the word. If we reach a node that does not have a child corresponding to the next digit, we create a new node and continue the process until all the words are inserted. The resulting Patricia tree will have each word stored in a leaf node, with the path from the root to the leaf representing the binary digits of the word.

Understanding the representation of these binary digits is crucial, much like in the binary and number systems, which form the basis for data type conversions in computing.


Searching in a Patricia tree involves traversing the tree from the root to a leaf, following the path defined by the binary digits of the search key. If the search key matches the string in a leaf node, the search is successful. Otherwise, the search key is not in the tree.

Deletion in a Patricia tree involves finding the leaf node that contains the string to be deleted, and then removing the path from the root to the leaf. If this results in an internal node having only one child, the node is also removed, and its child is connected directly to its parent. This ensures that the Patricia tree remains compressed after the deletion. The concept of deletion connects closely with the logical operations in trees, which discusses different strategies for manipulating tree data structures.

Additionally, understanding the types of data that can be efficiently managed and stored within such structures is discussed in detail in understanding data types, offering insights into how different data types are handled in computer science applications.

A-Level Computer Science Tutor Summary: A Patricia tree is a space-efficient data structure that speeds up the search, insertion, and deletion of strings. It's a special kind of tree that compacts parts where only one option exists, making operations quicker. Each node in the tree represents part of a string, and operations are done in time relative to the string's length. This tree helps manage data smartly and efficiently.

Study and Practice for Free

Trusted by 100,000+ Students Worldwide

Achieve Top Grades in your Exams with our Free Resources.

Practice Questions, Study Notes, and Past Exam Papers for all Subjects!

Need help from an expert?

4.93/5 based on546 reviews

The world’s top online tutoring provider trusted by students, parents, and schools globally.

Related Computer Science a-level Answers

    Read All Answers
    Loading...