11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 13.1 Tries 433000xxxx00xxxxx0xxxxxx1001xxxxx2 31xxxxxx1200101xxx4 24 4 5010101x2 7 32 37 40 42Figure 13.3 The PAT trie for the collection of values 2, 7, 24, 32, 37, 40, 42,120. Contrast this with the binary trie of Figure 13.1. In the PAT trie, all d<strong>at</strong>avalues are stored in the leaf nodes, while internal nodes store the bit position usedto determine the branching decision, assuming th<strong>at</strong> each key is represented as a 7-bit value representing a number in the range 0 to 127. Some of the branches in thisPAT trie have been labeled to indic<strong>at</strong>e the binary represent<strong>at</strong>ion for all values inth<strong>at</strong> subtree. For example, all values in the left subtree of the node labeled 0 musthave value 0xxxxxx (where x means th<strong>at</strong> bit can be either a 0 or a 1). All nodes inthe right subtree of the node labeled 3 must have value 0101xxx. However, we canskip branching on bit 2 for this subtree because all values currently stored have avalue of 0 for th<strong>at</strong> bit.The trie implement<strong>at</strong>ions illustr<strong>at</strong>ed by Figures 13.1 <strong>and</strong> 13.2 are potentiallyquite inefficient as certain key sets might lead to a large number of nodes with onlya single child. A variant on trie implement<strong>at</strong>ion is known as PATRICIA, whichst<strong>and</strong>s for “Practical <strong>Algorithm</strong> To Retrieve Inform<strong>at</strong>ion Coded In Alphanumeric.”In the case of a binary alphabet, a PATRICIA trie (referred to hereafter as a PATtrie) is a full binary tree th<strong>at</strong> stores d<strong>at</strong>a records in the leaf nodes. Internal nodesstore only the position within the key’s bit p<strong>at</strong>tern th<strong>at</strong> is used to decide on the nextbranching point. In this way, internal nodes with single children (equivalently, bitpositions within the key th<strong>at</strong> do not distinguish any of the keys within the currentsubtree) are elimin<strong>at</strong>ed. A PAT trie corresponding to the values of Figure 13.1 isshown in Figure 13.3.Example 13.1 When searching for the value 7 (0000111 in binary) inthe PAT trie of Figure 13.3, the root node indic<strong>at</strong>es th<strong>at</strong> bit position 0 (theleftmost bit) is checked first. Because the 0th bit for value 7 is 0, take theleft branch. At level 1, branch depending on the value of bit 1, which againis 0. At level 2, branch depending on the value of bit 2, which again is 0. Atlevel 3, the index stored in the node is 4. This means th<strong>at</strong> bit 4 of the key ischecked next. (The value of bit 3 is irrelevant, because all values stored inth<strong>at</strong> subtree have the same value <strong>at</strong> bit position 3.) Thus, the single branchth<strong>at</strong> extends from the equivalent node in Figure 13.1 is just skipped. Forkey value 7, bit 4 has value 1, so the rightmost branch is taken. Because

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!