Questions tagged [trie]

A tree-like data structure used to hold an associative array, also called a Prefix Tree.

Tries are specialized data structures where a word can be stored as a sequence of characters. Reading the word involves traversing down the branch of the tree. At each node, the possible completions of the partial word can be found by traversing down all possible paths to the leaf level. It is useful for implementing dictionary based functionality such as autocomplete.

1108 questions
6
votes
6 answers

Erlang: What is most-wrong with this trie implementation?

Over the holidays, my family loves to play Boggle. Problem is, I'm terrible at Boggle. So I did what any good programmer would do: wrote a program to play for me. At the core of the algorithm is a simple prefix trie, where each node is a dict of…
David Wolever
  • 148,955
  • 89
  • 346
  • 502
6
votes
3 answers

How to find possible English words in long random string?

I'm doing an artistic project where I want to see if any information emerges from a long string of characters (~28,000). It's sort of like the problem one faces in solving a Jumble. Here's a snippet:…
6
votes
3 answers

Generic Trie Haskell implementation

I needed a generic Trie implementation in Haskell but I could not find any. I was implemented my own functions (only keys here, I didn't need data on Trie) but I want to find a good Trie implementation in Haskell for future uses (I'm a rookie…
josejuan
  • 9,338
  • 24
  • 31
6
votes
1 answer

Sorting integers with a binary trie?

Since every integer can be represented as a series of bits of some length, it seems like you could sort a bunch of integers in the following way: Insert each integer into a binary trie (a trie where each node has two children, one labeled 0 and one…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
6
votes
1 answer

Very big string trie in Haskell

I need to load a few millions of short (length < 16) strings into a string trie in Haskell from the file and then to perform many very fast look-ups. What is the best way how to do that in Haskell? Would appreciate any strategy (package). Note: It…
Cartesius00
  • 23,584
  • 43
  • 124
  • 195
6
votes
5 answers

Looking for a good introduction on trie

I am looking for a good introduction/tutorial on Tries. Most of the links I find googling are either too succint and abstract for me or too trivial. Could someone please provide a good reference with examples in Java for me to study? Thanks
Jim
  • 18,826
  • 34
  • 135
  • 254
5
votes
1 answer

How do the tries work that are used in the mmo object format's symbol tables?

I try to understand, how the mmo object file format works, which is used for Don Knuth's educational MMIX architecture. I have not bought MMIXware, so I have to guess most of the details from the literate source files of the assembler and…
fuz
  • 88,405
  • 25
  • 200
  • 352
5
votes
2 answers

Prefix vs Suffix Trie in String Matching

I'm not too well-versed about the actual algorithms used in string matching with tries. I'm wondering why there seems to be more focus on suffix tries for string matching rather than prefix tries. Can we not use prefix tries for substring matching…
Mike
  • 85
  • 7
5
votes
2 answers

Why don't we use tries for sorting if they take O(n) time to sort a list?

Here is a description of an algorithm to sort strings using a trie: The algorithm first inserts all the items in the trie in O(n) time, where n is the total number of characters in the list of words to be sorted. Then it traverses the tree in-order,…
sonarforte
  • 1,588
  • 15
  • 18
5
votes
0 answers

Is there a Trie equivalent data structure in .NET?

I am looking for trie built-in implementation in .Net framework. Is there something similar to Trie in .Net data structures?
Deivydas Voroneckis
  • 1,973
  • 3
  • 19
  • 40
5
votes
2 answers

How does Perl's regex implementation makes use of tries?

I'm exploring ways to optimize a stack-based backtracking regex implementation (see also this thread). In the comments a hint about Perl's regex matcher was given. From the source code I already figured that it makes use of tries when matching a…
siracusa
  • 3,286
  • 1
  • 10
  • 19
5
votes
1 answer

Construct flame graph from trie

I have some stats in a trie which is generated periodically. I want to generate flame graphs on the difference between two tries. How do I do that? t = pygtrie.StringTrie(separator=os.path.sep) for dirpath, unused_dirnames, filenames in…
Gyanendra Singh
  • 895
  • 2
  • 13
  • 30
5
votes
6 answers

Space efficient collection for strings with common prefixes - Java implementation

I need to store millions of string with common prefixes (they don't correspond to file system paths) in a Set like structure in memory, and query the Collection to see if a path exists. e.g. /path /path/1 /path/2 /path/1/a /path/1/b I want to store…
Joel
  • 29,538
  • 35
  • 110
  • 138
5
votes
1 answer

How to find all words on the Boggle board using Dynamic Programming?

I enrolled in the Algorithms, Part II course on Coursera, and one of the assignments is to solve the Boggle game: http://coursera.cs.princeton.edu/algs4/assignments/boggle.html The honor code requires that I don't publicly post the solution, so…
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
5
votes
3 answers

Search for multiple words by prefix (trie data structure)

How can I use a trie (or another data structure or algorithm) to efficiently search for multiple words by prefix? For example: suppose this is my data set: Alice Jones Bob Smith Bobby Walker John Doe (10000 names in total) A trie data structure…
compie
  • 10,135
  • 15
  • 54
  • 78