SlideShare a Scribd company logo
Tries : A Brief Analysis
ADITYA NIHAL KUMAR SINGH
2015UGCS061
What is a trie?
A trie is a tree-like data structure whose nodes store the letters of an alphabet. By
structuring the nodes in a particular way, words and strings can be retrieved from the
structure by traversing down a branch path of the tree.
There are a handful of different ways to represent something as seemingly simple as a set
of words. For example, a hash or dictionary is one that we’re probably familiar with, as is
as hash table.
But there’s another structure that was created to solve the very problem of representing a
set of words: a trie. The term “trie” comes from the word retrieval, and is usually
pronounced “try”, to distinguish it from other “tree” structures.
How does a trie
look like?
Where do the
letters of
different words
live if the root
node doesn’t
house them all?
Giving Trie
traversal a try
Pseudo code to check whether a single word
exists in a dictionary of words or not
boolean check(String s) {
for(every char in String s) {
if(child node is null) {
return false;
}
}
return true;
}
How do we insert the letters into their correct places?
Pseudo code for insertion into a tire
void insert(String s) {
for(every char in string s) {
if(child node belonging to current char is null) {
child node=new Node();
}
current_node=child_node;
}
}
HASH TABLE
Array + Linked List
Hash function is needed
Memory is not wasted as much
TRIE
Array + Pointers
No hash function is required
Takes up a lot of memory with
empty or null pointers
Hash Tables Vs Tries
How a trie changes as it grows?
As trie grows in size, less work must be done to add a value,
since the “intermediate nodes”, or the branches of the trie
have already been build up.
Each time we add a word’s letter, we need to look at 26
references, since there are only 26 possibilities in the
alphabet. This number never changes in the context of our
trie, so it is a constant value.
Big O notation of a Trie
The worst case runtime of creating a trie structure is
dependent on how many words the trie contains, and how
long they might potentially be. This is known as O(m.n)
time, where m is the longest word and n is the total number
of words.
The time of searching, inserting & deleting from a trie
depends on length of the word a and total number of words
: O(a.n)
Uses of Tries
Phone Book
Google search
T9 dictionary
Criminology
Linux commands completion
And many more…
Resources
Digit-based sorting and data structures, Professor Avrim Blum
Lecture Notes on Tries, Professor Frank Pfenning
Algorithms: Tries, Robert Sedgewick and Kevin Wayne
Tries, Brilliant Learning
Tries, Daniel Ellard
Tries, Harvard CS50
Thank you.

More Related Content

Similar to Tries

Mdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databasesMdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databases
Rafael Alvarado
 
Ilja state2014expressivity
Ilja state2014expressivityIlja state2014expressivity
Ilja state2014expressivity
maartenmarx
 

Similar to Tries (20)

Trie Data Structure
Trie Data Structure Trie Data Structure
Trie Data Structure
 
Ir 03
Ir   03Ir   03
Ir 03
 
Thesaurus ppt.pptx
Thesaurus ppt.pptxThesaurus ppt.pptx
Thesaurus ppt.pptx
 
Aaai 2006 Pedersen
Aaai 2006 PedersenAaai 2006 Pedersen
Aaai 2006 Pedersen
 
6&7-Query Languages & Operations.ppt
6&7-Query Languages & Operations.ppt6&7-Query Languages & Operations.ppt
6&7-Query Languages & Operations.ppt
 
Souvenir's Booth - Algorithm Design and Analysis Project Project Report
Souvenir's Booth - Algorithm Design and Analysis Project Project ReportSouvenir's Booth - Algorithm Design and Analysis Project Project Report
Souvenir's Booth - Algorithm Design and Analysis Project Project Report
 
Mdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databasesMdst3705 2013-02-05-databases
Mdst3705 2013-02-05-databases
 
String Searching and Matching
String Searching and MatchingString Searching and Matching
String Searching and Matching
 
Shishirppt
ShishirpptShishirppt
Shishirppt
 
Ijcai 2007 Pedersen
Ijcai 2007 PedersenIjcai 2007 Pedersen
Ijcai 2007 Pedersen
 
Artificial intelligence and first order logic
Artificial intelligence and first order logicArtificial intelligence and first order logic
Artificial intelligence and first order logic
 
Python ppt_118.pptx
Python ppt_118.pptxPython ppt_118.pptx
Python ppt_118.pptx
 
Information retrieval chapter 2-Text Operations.ppt
Information retrieval chapter 2-Text Operations.pptInformation retrieval chapter 2-Text Operations.ppt
Information retrieval chapter 2-Text Operations.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
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
Ilja state2014expressivity
Ilja state2014expressivityIlja state2014expressivity
Ilja state2014expressivity
 
Elasticsearch V/s Relational Database
Elasticsearch V/s Relational DatabaseElasticsearch V/s Relational Database
Elasticsearch V/s Relational Database
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining
 
SIMILAR THESAURUS BASED ON ARABIC DOCUMENT: AN OVERVIEW AND COMPARISON
SIMILAR THESAURUS BASED ON ARABIC DOCUMENT: AN OVERVIEW AND COMPARISONSIMILAR THESAURUS BASED ON ARABIC DOCUMENT: AN OVERVIEW AND COMPARISON
SIMILAR THESAURUS BASED ON ARABIC DOCUMENT: AN OVERVIEW AND COMPARISON
 
Eacl 2006 Pedersen
Eacl 2006 PedersenEacl 2006 Pedersen
Eacl 2006 Pedersen
 

Recently uploaded

Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
AbrahamGadissa
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 

Recently uploaded (20)

Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 

Tries

  • 1. Tries : A Brief Analysis ADITYA NIHAL KUMAR SINGH 2015UGCS061
  • 2. What is a trie? A trie is a tree-like data structure whose nodes store the letters of an alphabet. By structuring the nodes in a particular way, words and strings can be retrieved from the structure by traversing down a branch path of the tree. There are a handful of different ways to represent something as seemingly simple as a set of words. For example, a hash or dictionary is one that we’re probably familiar with, as is as hash table. But there’s another structure that was created to solve the very problem of representing a set of words: a trie. The term “trie” comes from the word retrieval, and is usually pronounced “try”, to distinguish it from other “tree” structures.
  • 3. How does a trie look like?
  • 4. Where do the letters of different words live if the root node doesn’t house them all?
  • 6. Pseudo code to check whether a single word exists in a dictionary of words or not boolean check(String s) { for(every char in String s) { if(child node is null) { return false; } } return true; }
  • 7. How do we insert the letters into their correct places?
  • 8. Pseudo code for insertion into a tire void insert(String s) { for(every char in string s) { if(child node belonging to current char is null) { child node=new Node(); } current_node=child_node; } }
  • 9.
  • 10.
  • 11. HASH TABLE Array + Linked List Hash function is needed Memory is not wasted as much TRIE Array + Pointers No hash function is required Takes up a lot of memory with empty or null pointers Hash Tables Vs Tries
  • 12. How a trie changes as it grows? As trie grows in size, less work must be done to add a value, since the “intermediate nodes”, or the branches of the trie have already been build up. Each time we add a word’s letter, we need to look at 26 references, since there are only 26 possibilities in the alphabet. This number never changes in the context of our trie, so it is a constant value.
  • 13. Big O notation of a Trie The worst case runtime of creating a trie structure is dependent on how many words the trie contains, and how long they might potentially be. This is known as O(m.n) time, where m is the longest word and n is the total number of words. The time of searching, inserting & deleting from a trie depends on length of the word a and total number of words : O(a.n)
  • 14. Uses of Tries Phone Book Google search T9 dictionary Criminology Linux commands completion And many more…
  • 15. Resources Digit-based sorting and data structures, Professor Avrim Blum Lecture Notes on Tries, Professor Frank Pfenning Algorithms: Tries, Robert Sedgewick and Kevin Wayne Tries, Brilliant Learning Tries, Daniel Ellard Tries, Harvard CS50