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
12
votes
2 answers

Which node data structure to use for a trie

I am using trie for the first time.I wanted to know which is the best data structure to use for a trie while deciding which is the next branch that one is supposed to traverse. I was looking among an array,a hashmap and a linked list.
dilip devaraj
  • 261
  • 1
  • 2
  • 7
12
votes
1 answer

What is the most optimal way to store a trie for typeahead suggestions in distributed systems?

I have been reading a bit about tries, and how they are a good structure for typeahead designs. Aside from the trie, you usually also have a key/value pair for nodes and pre-computed top-n suggestions to improve response times. Usually, from what…
12
votes
8 answers

O(1) algorithm to determine if node is descendant of another node in a multiway tree?

Imagine the following tree: A / \ B C / \ \ D E F I'm looking for a way to query if for example F is a descendant of A (note: F doesn't need to be a direct descendant of A), which, in this particular case would be true. Only a…
Philip Kamenarsky
  • 2,757
  • 2
  • 24
  • 30
12
votes
3 answers

Which is a better implementation to implement a trie node's children - array or hashmap?

I am reading about trie data structure and found two implementations to implement the children in trie node. Following are the details of the two implementations :- 1) Trie node array of length 26 has been used to store children of the trie node. 2)…
ashisahu
  • 357
  • 3
  • 9
12
votes
4 answers

Clojure: How to generate a 'trie'?

Given the following... (def inTree '((1 2) (1 2 3) (1 2 4 5 9) (1 2 4 10 15) (1 2 4 20 25))) How would you transform it to this trie? (def outTrie '(1 (2 () (3 ()) (4 (5 (9 ())) (10 …
Johnny
  • 1,144
  • 2
  • 11
  • 23
11
votes
3 answers

Is there any way I can speed up this VBA algorithm?

I am looking to implement a VBA trie-building algorithm that is able to process a substantial English lexicon (~50,000 words) in a relatively short amount of time (less than 15-20 seconds). Since I am a C++ programmer by practice (and this is my…
GRB
  • 3,982
  • 4
  • 27
  • 21
11
votes
4 answers

Longest Prefix Matches for URLs

I need information about any standard python package which can be used for "longest prefix match" on URLs. I have gone through the two standard packages http://packages.python.org/PyTrie/#pytrie.StringTrie & 'http://pypi.python.org/pypi/trie/0.1.1'…
Amit
  • 614
  • 1
  • 8
  • 18
11
votes
1 answer

How Immutability is Implemented

I am trying to grasp how the trie and such in immutability is implemented, as relates to immutability in JS. I understand how there is supposed to be significant structural sharing. My question is say you have a graph sort of structure like this: a…
Lance
  • 75,200
  • 93
  • 289
  • 503
11
votes
2 answers

Autocomplete using a trie

I am working on an autocompletion script and was thinking about using a trie. My problem is I want everything that matches to be returned. So for example I type in the letter r I want all entries starting with r to be returned. Then all entries…
qw3n
  • 6,236
  • 6
  • 33
  • 62
11
votes
1 answer

Data structure to search name of files and get its path

I will be inserting names of files in a dynamically way, approximately till 1 billion of names. Besides, I do also want to store the path where the files are located in order to do the following queries: Searching wheter the name of a file is…
user4029213
11
votes
1 answer

How to scale a trie across multiple servers

Does anyone know how I might scale a Trie across multiple machines? Say the first machine runs out of space and I need to add more words from a very large dictionary, what might I do to add more words? (I am a Java thinker, but I believe the answer…
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
11
votes
10 answers

Getting a list of words from a Trie

I'm looking to use the following code to not check whether there is a word matching in the Trie but to return a list all words beginning with the prefix inputted by the user. Can someone point me in the right direction? I can't get it working at…
user330572
  • 183
  • 1
  • 2
  • 12
11
votes
2 answers

Implementing a Patricia Trie for use as a dictionary

I'm attempting to implement a Patricia Trie with the methods addWord(), isWord(), and isPrefix() as a means to store a large dictionary of words for quick retrieval (including prefix search). I've read up on the concepts but they just aren't…
Regis Frey
  • 888
  • 1
  • 11
  • 21
11
votes
1 answer

Trie implementation in Guava?

In the past Google Collections included an implementation of a TRIE. Is there any TRIE implementation in Guava? I need an efficient way to find common prefixes in a set of strings.
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
11
votes
3 answers

Search a string as you type the character

I have contacts stored in my mobile. Lets say my contacts are Ram Hello Hi Feat Eat At When I type letter 'A' I should get all the matching contacts say "Ram, Feat, Eat, At". Now I type one more letter T. Now my total string is "AT" now my…
user875036
  • 319
  • 2
  • 12
1 2
3
73 74