Chapter 12 Digital Search Structures

Similar documents
ECE697AA Lecture 20. Forwarding Tables

Trees. (Trees) Data Structures and Programming Spring / 28

Binary Trees, Binary Search Trees

Growth of the Internet Network capacity: A scarce resource Good Service

R16 SET - 1 '' ''' '' ''' Code No: R

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Message Switch. Processor(s) 0* 1 100* 6 1* 2 Forwarding Table

Radix Searching. The insert procedure for digital search trees also derives directly from the corresponding procedure for binary search trees:

Last Lecture: Network Layer

CSCI 104 Tries. Mark Redekopp David Kempe

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Need Backtracking! L 0 A 1 B 2 K 3 P 4 C 5 I 6 Z 7 S 8 A 9 N 10 X 11 A 12 N 13 X 14 P 15

Switch and Router Design. Packet Processing Examples. Packet Processing Examples. Packet Processing Rate 12/14/2011

Review on Tries for IPv6 Lookups

A set of nodes (or vertices) with a single starting point

Multiway Range Trees: Scalable IP Lookup with Fast Updates

Data Structures and Algorithms. Course slides: Radix Search, Radix sort, Bucket sort, Patricia tree

Multi-Way Search Tree

Recursively Partitioned Static IP Router-Tables *

Efficient Construction Of Variable-Stride Multibit Tries For IP Lookup

What is a Multi-way tree?

CS 206 Introduction to Computer Science II

Search trees, binary trie, patricia trie Marko Berezovský Radek Mařík PAL 2012

Multiway Range Trees: Scalable IP Lookup with Fast Updates

Organizing Spatial Data

CS 206 Introduction to Computer Science II

Objectives. Upon completion you will be able to:

More Binary Search Trees AVL Trees. CS300 Data Structures (Fall 2013)

Final Examination CSE 100 UCSD (Practice)

More BSTs & AVL Trees bstdelete

OPPA European Social Fund Prague & EU: We invest in your future.

Frugal IP Lookup Based on a Parallel Search

EE 368. Weeks 5 (Notes)

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

M-ary Search Tree. B-Trees. B-Trees. Solution: B-Trees. B-Tree: Example. B-Tree Properties. Maximum branching factor of M Complete tree has height =

Dictionaries. Priority Queues

IP Forwarding. CSU CS557, Spring 2018 Instructor: Lorenzo De Carli

TREES. Trees - Introduction

Multiway Search Trees. Multiway-Search Trees (cont d)

Scalable Lookup Algorithms for IPv6

Midterm Review. Congestion Mgt, CIDR addresses,tcp processing, TCP close. Routing. hierarchical networks. Routing with OSPF, IS-IS, BGP-4

CSE 100 Advanced Data Structures

Data Structures and Algorithms for Engineers

PART IV. Given 2 sorted arrays, What is the time complexity of merging them together?

Lecture Notes on Tries

Forwarding and Routers : Computer Networking. Original IP Route Lookup. Outline

Binary Search Trees. Analysis of Algorithms

Balanced Search Trees. CS 3110 Fall 2010

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

Trees. Prof. Dr. Debora Weber-Wulff

M-ary Search Tree. B-Trees. Solution: B-Trees. B-Tree: Example. B-Tree Properties. B-Trees (4.7 in Weiss)

Algorithms. AVL Tree

Balanced Trees Part One

Binary Trees

CIS265/ Trees Red-Black Trees. Some of the following material is from:

Fast binary and multiway prefix searches for packet forwarding

CSI 402 Spring 2014 Programming Assignment I 1 / 15

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

CS419: Computer Networks. Lecture 6: March 7, 2005 Fast Address Lookup:

Some Search Structures. Balanced Search Trees. Binary Search Trees. A Binary Search Tree. Review Binary Search Trees

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Succinct Representation Of Static Packet Classifiers

Lecture Notes on Tries

CS350: Data Structures Red-Black Trees

Lecture Notes on Tries

CSE 530A. B+ Trees. Washington University Fall 2013

Succinct Representation Of Static Packet Classifiers

B-Trees. CS321 Spring 2014 Steve Cutchin

Trees, Binary Trees, and Binary Search Trees

Friday Four Square! 4:15PM, Outside Gates

Efficient Implementation of Suffix Trees

Fall, 2015 Prof. Jungkeun Park

Power Efficient IP Lookup with Supernode Caching

Trees. Truong Tuan Anh CSE-HCMUT

Self-Balancing Search Trees. Chapter 11

CS301 - Data Structures Glossary By

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

Binary Search Schemes for Fast IP Lookups

Routing Lookup Algorithm for IPv6 using Hash Tables

Data Structures and Algorithms(12)

Data Structures. Binary Trees. Root Level = 0. number of leaves:?? leaves Depth (Maximum level of the tree) leaves or nodes. Level=1.

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

B-Trees. Introduction. Definitions

Algorithms and Data Structures

CS 268: Route Lookup and Packet Classification

Search Trees: BSTs and B-Trees

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Recursion Problems. Warm Ups. Enumeration 1 / 7

B-Trees. Disk Storage. What is a multiway tree? What is a B-tree? Why B-trees? Insertion in a B-tree. Deletion in a B-tree

Sorting and Searching

Trees: examples (Family trees)

SFU CMPT Lecture: Week 9

Efficient IP-Address Lookup with a Shared Forwarding Table for Multiple Virtual Routers

Router Design: Table Lookups and Packet Scheduling EECS 122: Lecture 13

FPGA Implementation of Lookup Algorithms

Predecessor. Predecessor Problem van Emde Boas Tries. Philip Bille

Red-Black, Splay and Huffman Trees

Define the red- black tree properties Describe and implement rotations Implement red- black tree insertion

Trees. Trees. CSE 2011 Winter 2007

CHAPTER 10 AVL TREES. 3 8 z 4

Transcription:

Chapter Digital Search Structures Digital Search Trees Binary Tries and Patricia Multiway Tries C-C Tsai P. Digital Search Tree A digital search tree is a binary tree in which each node contains one element. Assume fixed number of bits. Not empty => Root contains one dictionary pair (any pair). All remaining pairs whose key begins with a are in the left subtree. All remaining pairs whose key begins with a are in the right subtree. Left and right subtrees are digital subtrees on remaining bits. C-C Tsai P.

Example of Digital Search Tree Start with an empty digital search tree and insert a pair whose key is. Now, insert a pair whose key is. Now, insert a pair whose key is. C-C Tsai P. Example Now, insert a pair whose key is. Now, insert a pair whose key is. C-C Tsai P.4

Search/Insert/Delete Complexity of each operation is O(#bits in a key). #key comparisons = O(height). Expensive when keys are very long. C-C Tsai P.5 Applications of Digital Search Trees Analog of radix sort to searching. Keys are binary bit strings. Fixed length,,,. Variable length,,,. Application IP routing, packet classification, firewalls. IPv4 bit IP address. IPv6 8 bit IP address. C-C Tsai

Binary Trie Information Retrieval. At most one key comparison per operation, search/insert/delete. A Binary trie (pronounced try) is a binary tree that has two kinds of nodes: branch nodes and element nodes. For fixed length keys, Branch nodes: Left and right child pointers. No data field(s). Element nodes: No child pointers. Data field to hold dictionary pair. C-C Tsai P.7 Example of Binary Trie At most one key comparison for a search. C-C Tsai P.8 4

Variable Key Length Left and right child fields. Left and right pair fields. Left pair is pair whose key terminates at root of left subtree or the single pair that might otherwise be in the left subtree. Right pair is pair whose key terminates at root of right subtree or the single pair that might otherwise be in the right subtree. Field is null otherwise. C-C Tsai P.9 Example of Variable Key Length null At most one key comparison for a search. C-C Tsai P. 5

Fixed Length Insert Insert. Zero compares. C-C Tsai P. Fixed Length Insert Now, Insert C-C Tsai P. 6

Fixed Length Insert Insert C-C Tsai P. Fixed Length Insert Inserted. One compare. C-C Tsai P.4 7

Fixed Length Delete Now, Delete. C-C Tsai P.5 Fixed Length Delete Delete. One compare. C-C Tsai P.6 8

Fixed Length Delete Now, Delete. C-C Tsai P.7 Fixed Length Delete Delete. C-C Tsai P.8 9

Fixed Length Delete Delete. C-C Tsai P.9 Fixed Length Delete Delete. C-C Tsai P.

Fixed Length Delete Delete. One compare. C-C Tsai P. Fixed Length Join(S,m,B) Insert m into B to get B. S empty => B is answer; done. S is element node => insert S element into B ; done; B is element node => insert B element into S; done; If you get to this step, the roots of S and B are branch nodes. C-C Tsai P.

Fixed Length Join(S,m,B) S has empty right subtree. S a b B c J(a,b) J(S,B ) J(X,Y) join X and Y, all keys in X < all in Y. S has nonempty right subtree. Left subtree of B must be empty, because all keys in B > all keys in S. S a b B c Complexity = O(height). C-C Tsai P. a c J(S,B ) J(b,c) Compressed Binary Tries No branch node whose degree is. 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. C-C Tsai P.4

Example: Binary Trie 4 4 bit# field shown in black outside branch node. C-C Tsai P.5 Example: Compressed Binary Trie 4 4 bit# field shown in black outside branch node. #branch nodes = n. C-C Tsai P.6

Insert 4 4 Now, Insert. C-C Tsai P.7 Example: After Inserting 4 Now, Insert. 4 4 C-C Tsai P.8 4

Example: Insert 4 4 4 C-C Tsai P.9 Delete 4 4 4 Now, Delete. C-C Tsai P. 5

Example: After Deleting 4 4 Now, Delete. C-C Tsai P. Example: After Deleting 4 C-C Tsai P. 6

Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. All nodes in Patricia structure are of the same data type (binary tries use branch and element nodes). Pointers to only one kind of node. Simpler storage management. Uses a header node that has zero bitnumber. Remaining nodes define a trie structure that is the left subtree of the header node. (right subtree is not used) Trie structure is the same as that for the compressed binary trie. C-C Tsai Node Structure bit# LC Pair RC bit# = bit used for branching LC = left child pointer Pair = dictionary pair RC = right child pointer C-C Tsai P.4 7

Compressed Binary Trie To Patricia 4 4 Move each element into an ancestor or header node. C-C Tsai P.5 Example: Compressed Binary Trie To Patricia 4 4 C-C Tsai P.6 8

Insert Insert Insert 5 C-C Tsai P.7 Insert Now, Insert 5 Inserted 6 5 C-C Tsai P.8 9

Insert Insert 6 5 5 4 6 C-C Tsai P.9 Insert Insert 4 5 6 C-C Tsai P.4

Insert Insert 4 6 5 7 C-C Tsai P.4 Insert Inserted 4 6 5 6 7 C-C Tsai P.4

Delete Let p be the node that contains the dictionary pair that is to be deleted. Case : p has one self pointer. Case : p has no self pointer. C-C Tsai P.4 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 C-C Tsai P.44

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 Blue pointer could be red or black. q y C-C Tsai P.45 p Has No Self Pointer Use the key y in node q to find the unique node r that has a back pointer to node q. p q y r z C-C Tsai P.46

p Has No Self Pointer Copy the pair whose key is y to node p. p y q y r z C-C Tsai P.47 p Has No Self Pointer Change back pointer to q in node r to point to node p. p y q y r z C-C Tsai P.48 4

p Has No Self Pointer Change forward pointer to q from parent(q) to child of q. p y q y r z Node q now has been removed from trie. C-C Tsai P.49 Multiway Tries Key = Social Security Number. 44--5 9 decimal digits. -way trie (order trie). 4 5 6 7 8 9 C-C Tsai Height <=. 5

Social Security Trie -way trie Height <=. Search: <= 9 branches on digits plus compare. -way trie 44--5 Height <= 6. Search: <= 5 branches on digits plus compare. C-C Tsai P.5 Social Security AVL & Red-Black Red-black tree Height <= log 9 ~ 6. Search: <= 6 compares of 9 digit numbers. AVL tree Height <=.44log 9 ~ 4. Search: <= 4 compares of 9 digit numbers. Best binary tree. Height = log 9 ~. C-C Tsai P.5 6

Compressed Social Security Trie char# = character/digit used for branching. Equivalent to bit# field of compressed binary trie. #ptr = # of nonnull pointers in the node. char# #ptr 4 5 6 7 8 9 C-C Tsai P.5 Insert Insert 45678. 45678 Insert 54567. 5 : The rd digit is used for branching Null pointer fields not shown. 45678 54567 C-C Tsai P.54 7

Insert Insert 567. 5 45678 54567 C-C Tsai P.55 Insert Insert 79864. 5 45678 6 4 567 54567 C-C Tsai P.56 8

Insert Insert 4568. 7 5 79864 45678 6 4 567 54567 C-C Tsai P.57 Insert Insert 975. 7 5 79864 8 7 4 6 4568 45678 567 54567 C-C Tsai P.58 9

Insert 7 975 8 7 5 4 6 79864 4568 45678 567 54567 C-C Tsai P.59 Delete Delete 975. 7 975 8 7 5 4 6 79864 4568 45678 567 54567 C-C Tsai P.6

Delete Delete 45678. 5 7 79864 8 7 4 6 4568 45678 567 54567 C-C Tsai P.6 Delete Delete 567. 7 5 79864 4 6 4568 567 54567 C-C Tsai P.6

Delete 7 5 79864 4568 54567 C-C Tsai P.6 Variable Length Keys Problem arises only when one key is a (proper) prefix of another. 5 Insert 45678 4 6 567 54567 C-C Tsai P.64

Variable Length Keys Add a special end of key character (#) to each key to eliminate this problem. Insert 5 45678 4 6 567 54567 C-C Tsai P.65 Variable Length Keys Insert 5 5 4 # 4 6 45678 567 54567 End of key character (#) not shown. C-C Tsai P.66

Tries With Edge Information Add a new field (element) to each branch node. New field points to any one of the element nodes in the subtree. Use this pointer on way down to figure out skipped-over characters. C-C Tsai P.67 Example 5 5 4 # 6 4 45678 567 54567 element field shown in blue. C-C Tsai P.68 4

Trie Characteristics Expected height of an order m trie is ~log m n. Limit height to h (say 6). Level h branch nodes point to buckets that employ some other search structure for all keys in subtrie. Switch from trie scheme to simple array when number of pairs in subtrie becomes <= s (say s=6). Expected # of branch nodes for an order m trie when n is large and m and s are small is n/(s ln m). Sample digits from right to left (instead of from left to right) or using a pseudorandom number generator so as to reduce trie height. C-C Tsai P.69 Multibit Tries Variant of binary trie in which the number of bits (stride) used for branching may vary from node to node. Proposed for Internet router applications. Variable length prefixes. Longest prefix match. Limit height by choosing node strides. Root stride = => height =. Strides of 6, 8, and 8 for levels,, and => only levels. C-C Tsai P.7 5

Multibit Trie Example S = null S = S = C-C Tsai P.7 Multibit Tries Node whose stride is s uses s bits for branching. Node has s children and s element/prefix fields. Prefixes that end at a node are stored in that node. Short prefixes are expanded to length represented by node. When root stride is, prefixes whose length is < are expanded to length. P = * expands to P = * and P = *. If Q = * already exists P is eliminated because Q represents a longer match for any destination. C-C Tsai P.7 6