Data Structures & Algorithms Radix Search Richard Newman based on slides by S. Sahni and book by R. Sedgewick.

Slides:



Advertisements
Similar presentations
Introduction to Computer Science 2 Lecture 7: Extended binary trees
Advertisements

Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
1 Suffix Trees and Suffix Arrays Modern Information Retrieval by R. Baeza-Yates and B. Ribeiro-Neto Addison-Wesley, (Chapter 8)
Advanced Algorithm Design and Analysis (Lecture 4) SW5 fall 2004 Simonas Šaltenis E1-215b
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
Binary Search Trees Briana B. Morrison Adapted from Alan Eugenio.
Data Structures & Algorithms Radix Search Richard Newman based on slides by S. Sahni and book by R. Sedgewick.
Design a Data Structure Suppose you wanted to build a web search engine, a la Alta Vista (so you can search for “banana slugs” or “zyzzyvas”) index say.
Chapter 4: Trees Radix Search Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Binary Trees A binary tree is made up of a finite set of nodes that is either empty or consists of a node called the root together with two binary trees,
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
Lec 15 April 9 Topics: l binary Trees l expression trees Binary Search Trees (Chapter 5 of text)
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Chapter 4: Trees Binary Search Trees
Design a Data Structure Suppose you wanted to build a web search engine, a la Alta Vista (so you can search for “banana slugs” or “zyzzyvas”) index say.
CSE 373 Data Structures Lecture 15
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
A Summary of XISS and Index Fabric Ho Wai Shing. Contents Definition of Terms XISS (Li and Moon, VLDB2001) Numbering Scheme Indices Stored Join Algorithms.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
Sorting. Pseudocode of Insertion Sort Insertion Sort To sort array A[0..n-1], sort A[0..n-2] recursively and then insert A[n-1] in its proper place among.
Starting at Binary Trees
Binary Search Trees (10.1) CSE 2011 Winter November 2015.
1 Searching Searching in a sorted linked list takes linear time in the worst and average case. Searching in a sorted array takes logarithmic time in the.
Lec 15 Oct 18 Binary Search Trees (Chapter 5 of text)
1 Tries When searching for the name “Smith” in a phone book, we first locate the group of names starting with “S”, then within those we search for “m”,
1 CS 430: Information Discovery Lecture 4 Files Structures for Inverted Files.
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
Sets of Digital Data CSCI 2720 Fall 2005 Kraemer.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Chapter 4: Trees Part I: General Tree Concepts Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
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.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
1 Lexicographic Search:Tries All of the searching methods we have seen so far compare entire keys during the search Idea: Why not consider a key to be.
[Algo] MCPE CMU. Member Group Present 1.SUTTICHAI MESAARD SURIYA KONCHAIYAPHOM NATTHAWOOT PUNROOB WIWAT TAWEESUP
1 the BSTree class  BSTreeNode has same structure as binary tree nodes  elements stored in a BSTree are a key- value pair  must be a class (or a struct)
8/3/2007CMSC 341 BTrees1 CMSC 341 B- Trees D. Frey with apologies to Tom Anastasio.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Search Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
Tries 4/16/2018 8:59 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
Tries 07/28/16 11:04 Text Compression
Tries 5/27/2018 3:08 AM Tries Tries.
Multiway Search Trees Data may not fit into main memory
Mark Redekopp David Kempe
Tries 9/14/ :13 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
ITEC 2620M Introduction to Data Structures
Digital Search Trees & Binary Tries
Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use.
Data Structures and Algorithms for Information Processing
Data Structures and Algorithms for Information Processing
Search trees, binary trie, patricia trie
Digital Search Trees & Binary Tries
Binary Trees, Binary Search Trees
Tries 2/23/2019 8:29 AM Tries 2/23/2019 8:29 AM Tries.
Search trees, binary trie, patricia trie
CSC 143 Binary Search Trees.
Binary Trees, Binary Search Trees
Presentation transcript:

Data Structures & Algorithms Radix Search Richard Newman based on slides by S. Sahni and book by R. Sedgewick

Radix-based Keys Key has multiple parts Each part is an element of some set Character Numeral Key parts can be accessed (e.g., string s[i]) Size of set is radix

Advantages of Radix-based Search Good worst-case performance Simpler than balanced trees, etc. Fast access to data Easy way to handle variable-length keys Save space (part of key in structure)

Disadvantages of Radix-based Search May be space-inefficient Performance depends on access to bytes of keys Must have distinct keys, or other way to handle duplicate keys

Digital Search Trees Similar to binary search trees Difference is that we use bits of the key to determine subtree to search Path in tree = prefix of key

Digital Search Trees Insert A-S-E-R-C-H-I-N-G Key Repr A00001 S10011 E00101 R10010 C00011 H01000 I01001 N01110 G00111 A S 1 E R 10 C 1 0 H 10 I 10 N 10 G 10 Note that binary tree is not sorted in BST sense

Digital Search Trees Prop 15.1: A search or insertion into a DST takes about lg N comparisons on average, and about 2 lg N comparisons in the worst case, in a tree built from N keys. The number of comparisons is never more than the number of bits in the search key.

Tries Use bits of key to guide search like DST But keep keys in order like BST Allow recursive sort, etc. Pronounced “try-ee” or “try” Keys kept at leaves of a binary tree

Tries Defn. 15.1: A trie is a binary tree that has keys associated with each leaf, defined as follows: a trie for an empty set is a null link a trie for a single key is a leaf w/key a trie for > 1 key is an internal node with left link referring to trie for keys that start with 0, right for keys 1xxx

Tries Insert A-S-E-R-C-H-I-N-G Key Repr A00001 S10011 E00101 R10010 C00011 H01000 I01001 N01110 G00111 A S 1 A 0 Construct tree to point where prefixes match

Tries Insert A-S-E-R-C-H-I-N-G Key Repr A00001 S10011 E00101 R10010 C00011 H01000 I01001 N01110 G00111 A 10 AE RS S 10 A Construct tree to point where prefixes match

Tries Insert A-S-E-R-C-H-I-N-G Key Repr A00001 S10011 E00101 R10010 C00011 H01000 I01001 N01110 G A RS A 10 C E H

Tries Insert A-S-E-R-C-H-I-N- G Key Repr A00001 S10011 E00101 R10010 C00011 H01000 I01001 N01110 G RS A 10 C E H HI

Tries Prop. 15.2: The structure of a trie is independent of key insertion order; there is one unique trie for any given set of distinct keys. Prop. 15.3: Insertion or search for a random key in a trie built from N random keys takes about lg N bit comparisons on average, in the worst case, bounded by bits in key

Tries Annoying feature of tries: One-way branching when keys have common prefix Prop. 15.4: A trie built from N random w-bit keys has about N/lg 2 nodes on the average (about 1.44 N)

Patricia Tries Annoying feature of tries: One-way branching when keys have common prefix Two different types of nodes in trie Patricia tries: fix both of these Practical Algorithm To Retrieve Information Coded In Alphanumeric

Patricia Tries Avoid one-way branching: Keep at each node the index of the next bit to test Skip over common prefix! Avoid two types of nodes: Store data in internal nodes Replace external links with back links

Patricia Tries S R 4 H 0 1 E 2 3 C 4 A Key Repr A00001 S10011 E00101 R10010 C00011 H01000 I01001 N01110 G00111

Patricia Tries S R 4 H 0 1 E 2 3 C 4 A Key Repr A00001 S10011 E00101 R10010 C00011 H01000 I01001 N01110 G00111

Patricia Tries Prop 15.5: Insertion or search in a patricia trie built from N random bitstrings takes about lg N bit comparisons on average, and about 2 lg N in the worst case, but never more than the length of the key.

Map Radix search Digital Search Trees Tries Patricia Tries Multiway tries and TSTs Text string algorithms

Multiway Tries Like radix sort, can get benefit from comparing more than one bit at a time Compare r bits, speed up search by a factor of r What could possibly be bad? Number of links is now R=2 r Can waste a lot of space!

Multiway Tries Structure is (almost) the same as binary tries Except there are R branches Search: start at root, leftmost digit Follow i th link if next R-ary digit is i If null link, then miss If reach leaf, it contains only key with prefix matching path to it - compare

Existence Tries Only keys, no records Insert/search Defn. 15.2: The existence trie for a set of keys is: Empty set: null link Non-empty set: internal node with links for each possible digit to tries built with the leading digit omitted

Existence Tries Convenient to return null on miss, dummy record on hit Convenient to have no duplicate keys and no key a prefix of another key Keys of fixed length, or Use termination character with value NULLdigit, only used as sentinel

Existence Tries No need to store any data All keys captured in trie structure If reach NULLdigit at the same time we run out of key digits, search hit Otherwise, search miss Insert: search until find null link, then add nodes for each of the remaining digits in the key

Existence Tries t the time is now for n h e i i m e s o w f o r

Multi-way Tries R-ary branching Keys stored at leaves Path to leaf defines prefix of key stored at leaf Only build tree downward until prefixes become distinct

Multi-way Tries Defn. 15.3: The multiway trie for a set of keys associated with leaves is: Set empty: null link Singleton set: leaf with key Larger set: internal node with links for each possible digit to tries built with the leading digit omitted

Multi-way Tries Def

Summary Radix search Digital Search Trees Tries Patricia Tries Multiway tries and TSTs Text string algorithms