Presentation is loading. Please wait.

Presentation is loading. Please wait.

Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use.

Similar presentations


Presentation on theme: "Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use."— Presentation transcript:

1 Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use branch and element nodes). Pointers to only one kind of node. Simpler storage management.

2 Patricia Uses a header node.
Remaining nodes define a trie structure that is the left subtree of the header node. Trie structure is the same as that for the compressed binary trie of previous lecture.

3 Node Structure Pair bit# LC RC bit# = bit used for branching
LC = left child pointer Pair = dictionary pair RC = right child pointer

4 Compressed Binary Trie To Patricia
1 0001 0011 1000 1001 1100 1101 2 3 4 Replace each branch node with a Patricia node. Then move elements into ancestor Patricia nodes. There will always be one more element node than there are branch/Patricia nodes. The header nodes saves us by providing place for the additional element. Move each element into an ancestor or header node.

5 Compressed Binary Trie To Patricia
0001 1 1101 1 3 0011 2 1001 1 Red pointer (pointer to element or backward pointer) ends at a smaller or equal bit number than it starts at. Original pointers (forward pointers) end at a larger bit number. 1 4 4 1000 1100 1 1

6 Insert Insert 5 Insert

7 Insert 5 Insert 5 6 Insert

8 Insert 5 6 4 5 6 Insert

9 Insert 4 5 6 Insert

10 Insert 4 5 6 7 Insert

11 Insert 4 5 6 7 Insert

12 Delete Let p be the node that contains the dictionary pair that is to be deleted. Case 1: p has one self pointer. Case 2: p has no self pointer.

13 p Has One Self Pointer p = header => trie is now empty.
Set trie pointer to null. p != header => remove node p and update pointer to p. p p

14 p Has No Self Pointer Let q be the node that has a back pointer to p.
Node q was determined during the search for the pair with the delete key k. p y q Blue pointer could be red or black. Node q will be deleted! Move y to p and change back pointer to q so that it is a back pointer to p.

15 p Has No Self Pointer p q y z r Note that q and r may be the same node. Use the key y in node q to find the unique node r that has a back pointer to node q.

16 p Has No Self Pointer Copy the pair whose key is y to node p. 0001000
q z r y Copy the pair whose key is y to node p.

17 p Has No Self Pointer p y q z r y Change back pointer to q in node r to point to node p.

18 p Has No Self Pointer Node q now has been removed from trie.
y q y r Node q now has been removed from trie. z Change forward pointer to q from parent(q) to child of q.


Download ppt "Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use."

Similar presentations


Ads by Google