Binary Tries (continued)

Slides:



Advertisements
Similar presentations
Splay Trees Binary search trees.
Advertisements

Special Purpose Trees: Tries and Height Balanced Trees CS 400/600 – Data Structures.
Chapter 4: Trees Part II - AVL Tree
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
Binary Tries (continued) split(k). Similar to split algorithm for unbalanced binary search trees. Construct S and B on way down the trie. Follow with a.
Binary Search Trees Definition Of Binary Search Tree A binary tree. Each node has a (key, value) pair. For every node x, all keys in the left subtree.
Balanced Binary Search Trees
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
Red-Black Trees—Again rank(x) = # black pointers on path from x to an external node. Same as #black nodes (excluding x) from x to an external node. rank(external.
Higher Order Tries Key = Social Security Number.   9 decimal digits. 10-way trie (order 10 trie) Height
Binary Search Trees Dictionary Operations:  IsEmpty()  Search(key)  Insert(key, value)  Delete(key)
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
Searching with Structured Keys Objectives
Patricia P ractical A lgorithm T o R etrieve I nformation C oded I n A lphanumeric. Compressed binary trie. All nodes are of the same data type (binary.
Chapter 10 Search Structures Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures.
Binary Search Trees CSE, POSTECH. Search Trees Search trees are ideal for implementing dictionaries – Similar or better performance than skip lists and.
Red-Black Trees—Again rank(x) = # black pointers on path from x to an external node. Same as #black nodes (excluding x) from x to an external node. rank(external.
1 Multiway trees & B trees & 2_4 trees Go&Ta Chap 10.
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
ALGORITHMS FOR ISNE DR. KENNETH COSH WEEK 6.
BINARY SEARCH TREE. Binary Trees A binary tree is a tree in which no node can have more than two children. In this case we can keep direct links to the.
Analysis of Red-Black Tree Because of the rules of the Red-Black tree, its height is at most 2log(N + 1). Meaning that it is a balanced tree Time Analysis:
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
Binary Search Tree 황승원 Fall 2011 CSE, POSTECH 2 2 Search Trees Search trees are ideal for implementing dictionaries – Similar or better performance than.
Higher Order Tries Key = Social Security Number.   9 decimal digits. 10-way trie (order 10 trie) Height
Sets of Digital Data CSCI 2720 Fall 2005 Kraemer.
Chapter 7 Trees_Part3 1 SEARCH TREE. Search Trees 2  Two standard search trees:  Binary Search Trees (non-balanced) All items in left sub-tree are less.
Data Structures Using C++1 Chapter 5 Linked Lists.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Binary Search Trees (BST)
Binary Search Trees Dictionary Operations:  search(key)  insert(key, value)  delete(key) Additional operations:  ascend()  IndexSearch(index) (indexed.
Keeping Binary Trees Sorted. Search trees Searching a binary tree is easy; it’s just a preorder traversal public BinaryTree findNode(BinaryTree node,
Generic Trees—Trie, Compressed Trie, Suffix Trie (with Analysi
Patricia Tries CMSC 420.
Data Structure and Algorithms
File Organization and Processing Week 3
Lecture Efficient Binary Trees Chapter 10 of textbook
BCA-II Data Structure Using C
G64ADS Advanced Data Structures
B/B+ Trees 4.7.
Chapter 25 Binary Search Trees
Higher Order Tries Key = Social Security Number.
Binary Search Trees One of the tree applications in Chapter 10 is binary search trees. In Chapter 10, binary search trees are used to implement bags.
Multiway Search Trees Data may not fit into main memory
Azita Keshmiri CS 157B Ch 12 indexing and hashing
IP Routers – internal view
Splay Trees Binary search trees.
Binary Search Tree (BST)
Multiway search trees and the (2,4)-tree
Lecture 22 Binary Search Trees Chapter 10 of textbook
B+ Tree.
Digital Search Trees & Binary Tries
Binary Search Trees Dictionary Operations: Additional operations:
Splay Trees Binary search trees.
Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use.
Red-Black Trees—Again
Lec 12 March 9, 11 Mid-term # 1 (March 21?)
Multi-Way Search Trees
Binary Search Trees One of the tree applications in Chapter 10 is binary search trees. In Chapter 10, binary search trees are used to implement bags.
Digital Search Trees & Binary Tries
Higher Order Tries Key = Social Security Number.
Red-Black Trees—Again
Data Structures and Algorithms
Binary Trees, Binary Search Trees
(edited by Nadia Al-Ghreimil)
m-Way Search Trees A m-way Search tree of degree ‘m’ can have
Lecture 9: Intro to Trees
Chapter 12&13: Binary Search Trees (BSTs)
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Presentation transcript:

Binary Tries (continued) split(k). Similar to split algorithm for unbalanced binary search trees. Construct S and B on way down the trie. Follow with a backward cleanup pass over the constructed S and B.

Forward Pass a x b a to level j of S and to level j of B. Suppose you are at node x, which is at level j of the input trie. a x b If bit j of k is 1, move to root of b and add a to level j of S and to level j of B.

Forward Pass a x b b to level j of B and to level j of S. If bit j of k is 0, move to root of a and add b to level j of B and to level j of S.

Forward Pass Example S = null B = null b a c d e f g g is an element node. k = g.key = 101011

Forward Pass Example a S B b c d e f g k = g.key = 101011

Forward Pass Example a S B b c d e f g k = g.key = 101011

Forward Pass Example a S b B c d e f g k = g.key = 101011

Forward Pass Example c a S b B d e f g k = g.key = 101011

Forward Pass Example c a S b B e d f g k = g.key = 101011

Forward Pass Example e c a S d b B f k = g.key = 101011

Backward Cleanup Pass Retrace path from current nodes in S and B toward roots of respective tries. Eliminate branch nodes that are roots of subtries that have fewer than 2 dictionary pairs.

Backward Cleanup Pass Example f d b B Suppose f is an element node.

Backward Cleanup Pass Example Now backup on B. f

Backward Cleanup Pass Example Now backup on B. f

Backward Cleanup Pass Example Now backup on B. Assume root of d is a branch node. f

Backward Cleanup Pass Example Complexity of split is O(height). f

Compressed Binary Tries No branch node whose degree is 1. Add a bit# field to each branch node. bit# tells you which bit of the key to use to decide whether to move to the left or right subtrie.

Binary Trie bit# field shown in black outside branch node. 1 1 0001 1 0001 0011 1000 1001 1100 1101 2 3 4 4 bit# field shown in black outside branch node.

Compressed Binary Trie 1 1 3 2 1 1 0001 0011 4 4 1 1 1000 1001 1100 1101 bit# field shown in black outside branch node.

Compressed Binary Trie 1 0001 0011 1000 1001 1100 1101 2 3 4 #branch nodes = n – 1.

Insert 1 0001 0011 1000 1001 1100 1101 2 3 4 Insert 0010.

Insert 1 0001 1000 1001 1100 1101 2 3 4 0010 0011 Insert 0100.

Insert 1 1 2 2 1 1 3 0100 4 4 1 1 1 0001 4 1000 1001 1100 1101 1 0010 0011

Delete 0001 1 1000 1001 1100 1101 2 3 4 0010 0011 0100 Delete 0010.

Delete 0001 1 1000 1001 1100 1101 2 3 4 0011 0100 Delete 1001.

Delete 0001 1 1000 1100 1101 2 3 4 0011 0100

Split(k) Similar to splitting an uncompressed binary trie.

Join(S,m,B) 3-way to 2-way join Insert m into B to get B’. |S| <= 1 or |B’| = 1 handled as special cases as in the case of uncompressed tries. When |S| > 1 and |B’| > 1, let Smax be the largest key in S and let B’min be the smallest key in B’. Let d be the first bit that is different in Smax and B’min.

Cases To Consider B’ S d < min{bit#(S), bit#(B’)} 1 bit#(S) a b S c d B’ bit#(B’) d < min{bit#(S), bit#(B’)} d >= min{bit#(S), bit#(B’)} bit#(S) = bit#(B’) bit#(S) < bit#(B’) bit#(S) > bit#(B’) d >= min gives rise to 3 sub cases.

d < min{bit#(S), bit#(B’)} Bit d of Smax must be 0. 1 d S B’

bit#(S) = bit#(B’) 1 s a b S c d B’ Not possible, because keys in b are larger than those in c. However, all keys in S are supposed to be smaller than those in B’. Note, all branch nodes have 2 children in a compressed binary trie. Since d >= s, d=s and all keys in S and b agree on first d-1 bits.

bit#(S) < bit#(B’) = + B’ S 1 s a J(b,B’) 1 s a b 1 b’ c d 1 s a J(b,B’) 1 s a b S 1 b’ c d B’ = + All keys in B’ have bit s=1; otherwise all keys in B’ < those in b.

bit#(S) > bit#(B’) = + B’ S Smax and B’min are found just once. 1 1 b’ J(S,c) d 1 s a b S 1 b’ c d B’ = + Complexity is O(max{height(S), height(B)}). Smax and B’min are found just once.

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.

Compressed Binary Trie To Patricia 1 0001 0011 1000 1001 1100 1101 2 3 4 Move each element into an ancestor or header node.

Compressed Binary Trie To Patricia 1 2 3 4 0001 1101 0011 1100 1001 1000