SlideShare a Scribd company logo
1
Tries
• Standard Tries
• Compressed Tries
• Suffix Tries
2
Standard Tries
• The standard trie for a set of strings S is an ordered tree such that:
– each node but the root is labeled with a character
– the children of a node are alphabetically ordered
– the paths from the external nodes to the root yield the strings of S
• Example: standard trie for
the set of strings
S = { bear, bell, bid, bull,
buy, sell, stock, stop }
•A standard trie uses O(n) space. Operations (find, insert, remove) take time
O(dm) each, where:
-n = total size of the strings in S,
-m =size of the string parameter of the operation
-d =alphabet size,
3
Applications of Tries
• A standard trie supports the following operations on a preprocessed
text in time O(m), where m = |X|
-word matching: find the first occurence of word X in the text
-prefix matching: find the first occurrence of the longest prefix of
word X in the text
• Each operation is performed by tracing a path in the trie starting at the
root
4
Compressed Tries
• Trie with nodes of degree at least 2
• Obtained from standard trie by compressing chains of redundant
nodes
Compressed Trie:
Standard Trie:
5
Compact Storage of Compressed
Tries
• A compressed trie can be stored in space O(s), where s = |S|, by using
O(1) space index ranges at the nodes
6
Insertion and Deletion
into/from a Compressed Trie
7
Suffix Tries
• A suffix trie is a compressed trie for all the suffixes of a text
Example:
Compact representation:
8
Properties of Suffix Tries
• The suffix trie for a text X of size n from an alphabet of size d
-stores all the n(n-1)/2 suffixes of X in O(n) space
-supports arbitrary pattern matching and prefix matching queries in
O(dm) time, where m is the length of the pattern
-can be constructed in O(dn) time
9
Tries and Web Search Engines
• The index of a search engine (collection of all searchable words) is stored
into a compressed trie
• Each leaf of the trie is associated with a word and has a list of pages (URLs)
containing that word, called occurrence list
• The trie is kept in internal memory
• The occurrence lists are kept in external memory and are ranked by
relevance
• Boolean queries for sets of words (e.g., Java and coffee) correspond to set
operations (e.g., intersection) on the occurrence lists
• Additional information retrieval techniques are used, such as
– stopword elimination (e.g., ignore “the” “a” “is”)
– stemming (e.g., identify “add” “adding” “added”)
– link analysis (recognize authoritative pages)
10
Tries and Internet Routers
• Computers on the internet (hosts) are identified by a unique 32-bit IP
(internet protocol) addres, usually written in “dotted-quad-decimal” notation
• E.g., www.iitd.ac.in is 103.27.9.24
• Use nslookup on Unix to find out IP addresses
• An organization uses a subset of IP addresses with the same prefix, e.g.,
IITD uses 103.27.*.*, Yale uses 130.132.*.*
• Data is sent to a host by fragmenting it into packets. Each packet carries the
IP address of its destination.
• The internet whose nodes are routers, and whose edges are communication
links.
• A router forwards packets to its neighbors using IP prefix matching rules.
E.g., a packet with IP prefix 103.27. should be forwarded to the IITD
gateway router.
• Routers use tries on the alphabet 0,1 to do prefix matching.

More Related Content

PPT
Tries in data structures using C presentation
PPT
Tries .ppt
PPTX
TRIES_data_structure
PPTX
Shishirppt
PPT
PPTX
Trie (1)
PPTX
Tries data structures
PPTX
Data structure tries
Tries in data structures using C presentation
Tries .ppt
TRIES_data_structure
Shishirppt
Trie (1)
Tries data structures
Data structure tries

Similar to data structure and algorithm notes - tries (20)

PPTX
PDF
'Trie' Data Structure for Auto Search Complete
PPT
4888009.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PPTX
Suffix Tree and Suffix Array
PPTX
Application of tries
PPTX
Trie Logic.pptx for data structures and algorithms
PPTX
presentation on important DAG,TRIE,Hashing.pptx
PPTX
Tries - Tree Based Structures for Strings
PDF
SEARCH ENGINE 2015_11111111111111111.pdf
PDF
Souvenir's Booth - Algorithm Design and Analysis Project Project Report
PPTX
Image Captioning of Handwritten Mathematical Expressions
PPTX
Google code search
PDF
Pattern Matching Part One: Suffix Trees
PPTX
Lecture 7- Text Statistics and Document Parsing
PDF
Iaetsd effective method for searching substrings in large databases
PPT
Designing A Syntax Based Retrieval System03
PPTX
TRIES_PATRICIA.pptxnnnnnnnnnnnnnnnnnnnnnnnnn
PDF
Indexed matching statistics and shortest unique substrings
'Trie' Data Structure for Auto Search Complete
4888009.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Suffix Tree and Suffix Array
Application of tries
Trie Logic.pptx for data structures and algorithms
presentation on important DAG,TRIE,Hashing.pptx
Tries - Tree Based Structures for Strings
SEARCH ENGINE 2015_11111111111111111.pdf
Souvenir's Booth - Algorithm Design and Analysis Project Project Report
Image Captioning of Handwritten Mathematical Expressions
Google code search
Pattern Matching Part One: Suffix Trees
Lecture 7- Text Statistics and Document Parsing
Iaetsd effective method for searching substrings in large databases
Designing A Syntax Based Retrieval System03
TRIES_PATRICIA.pptxnnnnnnnnnnnnnnnnnnnnnnnnn
Indexed matching statistics and shortest unique substrings
Ad

Recently uploaded (20)

PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PPT
Total quality management ppt for engineering students
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPT
introduction to datamining and warehousing
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Abrasive, erosive and cavitation wear.pdf
PPTX
Artificial Intelligence
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Nature of X-rays, X- Ray Equipment, Fluoroscopy
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Total quality management ppt for engineering students
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Soil Improvement Techniques Note - Rabbi
Automation-in-Manufacturing-Chapter-Introduction.pdf
III.4.1.2_The_Space_Environment.p pdffdf
introduction to datamining and warehousing
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Exploratory_Data_Analysis_Fundamentals.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Fundamentals of safety and accident prevention -final (1).pptx
Abrasive, erosive and cavitation wear.pdf
Artificial Intelligence
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Ad

data structure and algorithm notes - tries

  • 1. 1 Tries • Standard Tries • Compressed Tries • Suffix Tries
  • 2. 2 Standard Tries • The standard trie for a set of strings S is an ordered tree such that: – each node but the root is labeled with a character – the children of a node are alphabetically ordered – the paths from the external nodes to the root yield the strings of S • Example: standard trie for the set of strings S = { bear, bell, bid, bull, buy, sell, stock, stop } •A standard trie uses O(n) space. Operations (find, insert, remove) take time O(dm) each, where: -n = total size of the strings in S, -m =size of the string parameter of the operation -d =alphabet size,
  • 3. 3 Applications of Tries • A standard trie supports the following operations on a preprocessed text in time O(m), where m = |X| -word matching: find the first occurence of word X in the text -prefix matching: find the first occurrence of the longest prefix of word X in the text • Each operation is performed by tracing a path in the trie starting at the root
  • 4. 4 Compressed Tries • Trie with nodes of degree at least 2 • Obtained from standard trie by compressing chains of redundant nodes Compressed Trie: Standard Trie:
  • 5. 5 Compact Storage of Compressed Tries • A compressed trie can be stored in space O(s), where s = |S|, by using O(1) space index ranges at the nodes
  • 7. 7 Suffix Tries • A suffix trie is a compressed trie for all the suffixes of a text Example: Compact representation:
  • 8. 8 Properties of Suffix Tries • The suffix trie for a text X of size n from an alphabet of size d -stores all the n(n-1)/2 suffixes of X in O(n) space -supports arbitrary pattern matching and prefix matching queries in O(dm) time, where m is the length of the pattern -can be constructed in O(dn) time
  • 9. 9 Tries and Web Search Engines • The index of a search engine (collection of all searchable words) is stored into a compressed trie • Each leaf of the trie is associated with a word and has a list of pages (URLs) containing that word, called occurrence list • The trie is kept in internal memory • The occurrence lists are kept in external memory and are ranked by relevance • Boolean queries for sets of words (e.g., Java and coffee) correspond to set operations (e.g., intersection) on the occurrence lists • Additional information retrieval techniques are used, such as – stopword elimination (e.g., ignore “the” “a” “is”) – stemming (e.g., identify “add” “adding” “added”) – link analysis (recognize authoritative pages)
  • 10. 10 Tries and Internet Routers • Computers on the internet (hosts) are identified by a unique 32-bit IP (internet protocol) addres, usually written in “dotted-quad-decimal” notation • E.g., www.iitd.ac.in is 103.27.9.24 • Use nslookup on Unix to find out IP addresses • An organization uses a subset of IP addresses with the same prefix, e.g., IITD uses 103.27.*.*, Yale uses 130.132.*.* • Data is sent to a host by fragmenting it into packets. Each packet carries the IP address of its destination. • The internet whose nodes are routers, and whose edges are communication links. • A router forwards packets to its neighbors using IP prefix matching rules. E.g., a packet with IP prefix 103.27. should be forwarded to the IITD gateway router. • Routers use tries on the alphabet 0,1 to do prefix matching.