SlideShare a Scribd company logo
1 of 18
TRIE
(AN ADVANCED DATA STRUCTURE)
By: SHISHIR SINGHAL
1
CONTENTS
Introduction
Why Tries?
Types of Tries
Standard Tries
Standard Trie – Insertion
Standard Trie – Searching
Analysis
Compressed Tries
Advantages and Disadvantages
Applications
Conclusion 2
INTRODUCTION
 In Computer Science,
trie are also called
Digital Trees,
sometimes Radix
trees, and Prefix Trees.
 It is an ordered Data
Structure that is used
to store dynamic sets
or associative arrays
where key are usually
STRINGS.
3
WHY TRIES?
 Preprocessing the pattern speeds up pattern matching
queries.
 After preprocessing the pattern, KMP’s algorithm
performs pattern matching in time proportional to the
text size.
 If the text is large, immutable and searched for often (e.g.,
works by Shakespeare), we may want to preprocess the text
instead of the pattern.
 A trie is a compact data structure for representing a set of
strings, such as all the words in a text
 A tries supports pattern matching queries in time
proportional to the pattern size
4
TYPES OF TRIES
Standard
Tries
Compressed
Tries
5
STANDARD TRIE
6
Let S be set strings.
S={ bear, bell, bid, bull, buy, sell, stock, stop }
Observations:
o The children of a node are alphabetically ordered.
o The paths from the external nodes to the root yield
the strings of S.
STANDARD TRIE - INSERTION
algorithm insert(root: node, s: string, value: any):
node = root
i = 0
n = length(s)
while(i<n):
if node.child (s [ i ] ) ! = nil
node = node.child (s [ i ] )
i = i+1
else:
break
(*append a new node, if necessary*)
while(i<n):
node.child (s [ i ] ) = new node
node = node.child ( s [ i ] )
i = i+1
node.value = value 7
root
Let S be a set strings to be inserted,
S={ bear, bell, bid, bull, buy, sell, stock,
stop}
i
s
p
(39)
d
(5,14)
l
l
(9)
u
l
l
y
(17,26)
(22)
e
l
l
(30)
t
o
c
k
(34,43)
b
e
a
r
(1)
STANDARD TRIE - SEARCHING
algorithm find(node, key):
for char in key:
if char is not in node.child:
return null
else:
node = node.child[char]
return node.value
Operations:
find(node, ”bear”)
return (1)
find(node, “stock”)
return (34,43)
find(node, “best”)
return null 88
root
i
p
(39)
d
(5,14)
l
l
(9)
u
l
l
y
(17,26)
(22)
e
l
l
(30)
s
t
o
c
k
(34,43)
b
e
a
r
(1)
Let S be a set strings presents in a trie,
S={ bear, bell, bid, bull, buy, sell, stock, stop}
ANALYSIS
9
 Space Complexity:
 O(n) for insertion, searching and deletion.
 Time Complexity:
 O(dm) for insertion, searching and deletion
Where:
n : total size of the strings in S.
m : size of the string parameter in operations.
d : size of the alphabet. i,e
26 in case each character is of small english alphabet,
2 in case of binary numbers, and
so on…….
COMPRESSED TRIES
 It is obtained from standard trie by compressing the chain of
“redundant” nodes in such a way that each nodes has at least two
childrens.
10
Standard Trie Compressed Trie
Continue……
 Problem with Standard trie
 We cannot search for a substring of a particular string in a text because
standard trie is based on prefix matching.
 So to handle this situation, we can use compressed tries.
 Therefore, instead of storing the substrings, we store the range of indices in
a nodes of compressed trie.
 Compressed Trie uses O(n) space, where n is no. of strings in an array
which is much efficient as standard trie.
11
Suppose strings in a text is stored in an array of strings:
ADVANTAGES AND DISADVANTAGES
 Advantages:
 Looking up data in a trie is faster in the worst case, O(m) time (where m is the length
of a search string), compared to an imperfect hash table. An imperfect hash table can
have key collisions
 There are no collisions of different keys in a trie.
 There is no need to provide a hash function or to change hash functions as more keys
are added to a trie.
 A trie can provide an alphabetical ordering of the entries by key.
 Disadvantages:
 Tries can be slower in some cases than hash tables for looking up data, especially if
the data is directly accessed on a hard disk drive or some other secondary storage
device where the random-access time is high compared to main memory
 Some keys, such as floating point numbers, can lead to long chains and prefixes that
are not particularly meaningful
 Some tries can require more space than a hash table, as memory may be allocated for
each character in the search string 12
APPLICATIONS
 In Web search and contact search
 Auto complete feature is widely used in internet and mobile apps. A lot
of websites and apps try to complete your input as soon as you start
typing.
13
Continue…
 In URL search in a web browser
 Tries is also be used to store the browser history.
 In Application search in windows OS
14
Continue…
 In Routing table
 For example, consider this IPv4 routing table(CIDR notation is
used):
 192.168.20.16/28
 192.168.0.0/16
 When the address 192.168.20.19 needs to look up in the trie
of network addresses, both the entries in the routing table
“match”.
 In this case, the longest prefix of the candidate routes is
192.168.20.16/28, since its subnet mask is higher the other
entry’s mask.
 Therefore, tries help router to fast lookup the destination
network of an IP packet.
15
CONCLUSION
 Tries are more space efficient when they contain a large
number of short keys, because nodes are shared between
keys with common initial subsequences.
 Tries facilitate longest-prefix matching, helping to find
the key sharing the longest possible prefix of characters
all unique.
 So because of its efficiency and amazing real life
applications, it is recommended for soft. Engg to learn
TRIE data structure.
16
REFERENCES
 www.cse.iitd.ac.in/~saroj/DS/DS2014/Trie.pdf
 http://en.wikipedia.org/wiki/Trie
 infoscience.epfl.ch/record/64394/files/triesearches.pdf
 stackoverflow.com/.../where-do-i-find-a-standard-trie-
based-map-implementation.html
 Knuth, Donald (1997). "6.3: Digital Searching". The Art
of Computer Programming Volume 3: Sorting and
Searching (2nd ed.). Addison-Wesley. p. 492. ISBN 0-
201-89685
17
18

More Related Content

What's hot (20)

Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Graph & Heap in Data Structure (Basic Information)
Graph & Heap in Data Structure (Basic Information)Graph & Heap in Data Structure (Basic Information)
Graph & Heap in Data Structure (Basic Information)
 
7.basic array
7.basic array7.basic array
7.basic array
 
2. bit fields union enum
2. bit fields  union  enum2. bit fields  union  enum
2. bit fields union enum
 
Introduction to Ultra-succinct representation of ordered trees with applications
Introduction to Ultra-succinct representation of ordered trees with applicationsIntroduction to Ultra-succinct representation of ordered trees with applications
Introduction to Ultra-succinct representation of ordered trees with applications
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
 
Array
ArrayArray
Array
 
Lecft3data
Lecft3dataLecft3data
Lecft3data
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Array
ArrayArray
Array
 
Extensible hashing
Extensible hashingExtensible hashing
Extensible hashing
 
Lect9
Lect9Lect9
Lect9
 
Huffman coding01
Huffman coding01Huffman coding01
Huffman coding01
 
Java part 2
Java part  2Java part  2
Java part 2
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Arrays
ArraysArrays
Arrays
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Array
ArrayArray
Array
 
t-vMF Similarity
t-vMF Similarityt-vMF Similarity
t-vMF Similarity
 

Similar to Shishirppt

Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
Combining text and pattern preprocessing in an adaptive dna pattern matcher
Combining text and pattern preprocessing in an adaptive dna pattern matcherCombining text and pattern preprocessing in an adaptive dna pattern matcher
Combining text and pattern preprocessing in an adaptive dna pattern matcherIAEME Publication
 
Algorithm ch13.ppt
Algorithm ch13.pptAlgorithm ch13.ppt
Algorithm ch13.pptDreamless2
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxjainaaru59
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce AlgorithmsAmund Tveit
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparationKushaal Singla
 
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.pptLecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.pptiamsallauddin
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureRai University
 
Case study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureCase study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureHoneyChintal
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashingAkhil Prem
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureRai University
 

Similar to Shishirppt (20)

Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Tries
TriesTries
Tries
 
String Searching and Matching
String Searching and MatchingString Searching and Matching
String Searching and Matching
 
Combining text and pattern preprocessing in an adaptive dna pattern matcher
Combining text and pattern preprocessing in an adaptive dna pattern matcherCombining text and pattern preprocessing in an adaptive dna pattern matcher
Combining text and pattern preprocessing in an adaptive dna pattern matcher
 
Algorithm ch13.ppt
Algorithm ch13.pptAlgorithm ch13.ppt
Algorithm ch13.ppt
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptx
 
A survey of xml tree patterns
A survey of xml tree patternsA survey of xml tree patterns
A survey of xml tree patterns
 
ch13
ch13ch13
ch13
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce Algorithms
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
 
Tries .ppt
Tries .pptTries .ppt
Tries .ppt
 
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.pptLecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structure
 
Case study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structureCase study how pointer plays very important role in data structure
Case study how pointer plays very important role in data structure
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
 
Cs341
Cs341Cs341
Cs341
 
Sorting algorithm
Sorting algorithmSorting algorithm
Sorting algorithm
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
Numpy ndarrays.pdf
Numpy ndarrays.pdfNumpy ndarrays.pdf
Numpy ndarrays.pdf
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Shishirppt

  • 1. TRIE (AN ADVANCED DATA STRUCTURE) By: SHISHIR SINGHAL 1
  • 2. CONTENTS Introduction Why Tries? Types of Tries Standard Tries Standard Trie – Insertion Standard Trie – Searching Analysis Compressed Tries Advantages and Disadvantages Applications Conclusion 2
  • 3. INTRODUCTION  In Computer Science, trie are also called Digital Trees, sometimes Radix trees, and Prefix Trees.  It is an ordered Data Structure that is used to store dynamic sets or associative arrays where key are usually STRINGS. 3
  • 4. WHY TRIES?  Preprocessing the pattern speeds up pattern matching queries.  After preprocessing the pattern, KMP’s algorithm performs pattern matching in time proportional to the text size.  If the text is large, immutable and searched for often (e.g., works by Shakespeare), we may want to preprocess the text instead of the pattern.  A trie is a compact data structure for representing a set of strings, such as all the words in a text  A tries supports pattern matching queries in time proportional to the pattern size 4
  • 6. STANDARD TRIE 6 Let S be set strings. S={ bear, bell, bid, bull, buy, sell, stock, stop } Observations: o The children of a node are alphabetically ordered. o The paths from the external nodes to the root yield the strings of S.
  • 7. STANDARD TRIE - INSERTION algorithm insert(root: node, s: string, value: any): node = root i = 0 n = length(s) while(i<n): if node.child (s [ i ] ) ! = nil node = node.child (s [ i ] ) i = i+1 else: break (*append a new node, if necessary*) while(i<n): node.child (s [ i ] ) = new node node = node.child ( s [ i ] ) i = i+1 node.value = value 7 root Let S be a set strings to be inserted, S={ bear, bell, bid, bull, buy, sell, stock, stop} i s p (39) d (5,14) l l (9) u l l y (17,26) (22) e l l (30) t o c k (34,43) b e a r (1)
  • 8. STANDARD TRIE - SEARCHING algorithm find(node, key): for char in key: if char is not in node.child: return null else: node = node.child[char] return node.value Operations: find(node, ”bear”) return (1) find(node, “stock”) return (34,43) find(node, “best”) return null 88 root i p (39) d (5,14) l l (9) u l l y (17,26) (22) e l l (30) s t o c k (34,43) b e a r (1) Let S be a set strings presents in a trie, S={ bear, bell, bid, bull, buy, sell, stock, stop}
  • 9. ANALYSIS 9  Space Complexity:  O(n) for insertion, searching and deletion.  Time Complexity:  O(dm) for insertion, searching and deletion Where: n : total size of the strings in S. m : size of the string parameter in operations. d : size of the alphabet. i,e 26 in case each character is of small english alphabet, 2 in case of binary numbers, and so on…….
  • 10. COMPRESSED TRIES  It is obtained from standard trie by compressing the chain of “redundant” nodes in such a way that each nodes has at least two childrens. 10 Standard Trie Compressed Trie Continue……
  • 11.  Problem with Standard trie  We cannot search for a substring of a particular string in a text because standard trie is based on prefix matching.  So to handle this situation, we can use compressed tries.  Therefore, instead of storing the substrings, we store the range of indices in a nodes of compressed trie.  Compressed Trie uses O(n) space, where n is no. of strings in an array which is much efficient as standard trie. 11 Suppose strings in a text is stored in an array of strings:
  • 12. ADVANTAGES AND DISADVANTAGES  Advantages:  Looking up data in a trie is faster in the worst case, O(m) time (where m is the length of a search string), compared to an imperfect hash table. An imperfect hash table can have key collisions  There are no collisions of different keys in a trie.  There is no need to provide a hash function or to change hash functions as more keys are added to a trie.  A trie can provide an alphabetical ordering of the entries by key.  Disadvantages:  Tries can be slower in some cases than hash tables for looking up data, especially if the data is directly accessed on a hard disk drive or some other secondary storage device where the random-access time is high compared to main memory  Some keys, such as floating point numbers, can lead to long chains and prefixes that are not particularly meaningful  Some tries can require more space than a hash table, as memory may be allocated for each character in the search string 12
  • 13. APPLICATIONS  In Web search and contact search  Auto complete feature is widely used in internet and mobile apps. A lot of websites and apps try to complete your input as soon as you start typing. 13 Continue…
  • 14.  In URL search in a web browser  Tries is also be used to store the browser history.  In Application search in windows OS 14 Continue…
  • 15.  In Routing table  For example, consider this IPv4 routing table(CIDR notation is used):  192.168.20.16/28  192.168.0.0/16  When the address 192.168.20.19 needs to look up in the trie of network addresses, both the entries in the routing table “match”.  In this case, the longest prefix of the candidate routes is 192.168.20.16/28, since its subnet mask is higher the other entry’s mask.  Therefore, tries help router to fast lookup the destination network of an IP packet. 15
  • 16. CONCLUSION  Tries are more space efficient when they contain a large number of short keys, because nodes are shared between keys with common initial subsequences.  Tries facilitate longest-prefix matching, helping to find the key sharing the longest possible prefix of characters all unique.  So because of its efficiency and amazing real life applications, it is recommended for soft. Engg to learn TRIE data structure. 16
  • 17. REFERENCES  www.cse.iitd.ac.in/~saroj/DS/DS2014/Trie.pdf  http://en.wikipedia.org/wiki/Trie  infoscience.epfl.ch/record/64394/files/triesearches.pdf  stackoverflow.com/.../where-do-i-find-a-standard-trie- based-map-implementation.html  Knuth, Donald (1997). "6.3: Digital Searching". The Art of Computer Programming Volume 3: Sorting and Searching (2nd ed.). Addison-Wesley. p. 492. ISBN 0- 201-89685 17
  • 18. 18