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
10
votes
5 answers

Optimal data structure for a special dictionary

Which data structure is best in terms of computational complexity to implement a dictionary of (key,val) items, which must support only following commands: Insert(key) - appends an item (key,val) with val=1 Increment(key) - increments val of…
psihodelia
  • 29,566
  • 35
  • 108
  • 157
10
votes
5 answers

Are Tries still a good idea on modern architectures?

One of my favourite data structures in college was the Trie. It's a great data structure for holding a large set of strings if the prefixes are shared. Lookups are also nice, since they are done at O(|length|) of the string regardless of how many…
Uri
  • 88,451
  • 51
  • 221
  • 321
10
votes
3 answers

Given a list of words and a sentence find all words that appear in the sentence either in whole or as a substring

Problem Given a list of string find the strings from the list that appear in the given text. Example list = ['red', 'hello', 'how are you', 'hey', 'deployed'] text = 'hello, This is shared right? how are you doing tonight' result = ['red', 'how…
thebenman
  • 1,621
  • 14
  • 35
10
votes
1 answer

marisa trie suffix compression?

I'm using a custom Cython wrapper of this marisa trie library as a key-value multimap. My trie entries look like key 0xff data1 0xff data2 to map key to the tuple (data1, data2). data1 is a string of variable length but data2 is always a 4-byte…
gmoss
  • 1,019
  • 5
  • 17
10
votes
2 answers

Disk-based trie?

I'm trying to build a Trie but on a mobile phone which has very limited memory capacity. I figured that it is probably best that the whole structure be stored on disk, and only loaded as necessary since I can tolerate a few disk reads. But, after a…
chakrit
  • 61,017
  • 25
  • 133
  • 162
10
votes
3 answers

Stuck on a Iterator Implementation of a Trie

I have to implement a homemade Trie and I'm stuck on the Iterator part. I can't seem to figure out the increment method for the trie. I hope someone can help me clear things out. Here's the code for the Iterator: template class…
user44447
  • 141
  • 2
  • 6
10
votes
2 answers

HAT-trie in ANSI C implementation?

I am looking for ANSI C HAT-trie implementation released under some free license. I have not found one. Can you point me to some standalone implementation or a program that uses HAT-tries to get at least slight idea how to implement it the roght…
mjf
  • 101
  • 1
  • 3
10
votes
3 answers

What's the size of a prefix tree (trie) that contains all the english words?

Knowing that there are about 200k words in the english dictionary and the alphabet has 26 letters or so.
Raul
  • 1,899
  • 2
  • 20
  • 32
9
votes
3 answers

Algorithms for compression of set tries

I have a collection of sets that I'd like to place in a trie. Normal tries are made of strings of elements - that is, the order of the elements is important. Sets lack a defined order, so there's the possibility of greater compression. For example,…
rampion
  • 87,131
  • 49
  • 199
  • 315
9
votes
2 answers

How to free recursive struct (trie)

FINAL EDIT My function that frees the memory works properly, and as milevyo has suggested, the problem lies in node creation, which I had fixed. I now have a separate problem where the program segfaults when run normally, but it cannot be reproduced…
jiewpeng
  • 333
  • 2
  • 8
9
votes
4 answers

Persisting a trie to a file - C

I have a trie which I am using to do some string processing. I have a simple compiler which generates trie from some data. Once generated, my trie won't change at run time. I am looking for an approach where I can persist the trie in a file and…
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
9
votes
2 answers

Clojure Zipper of nested Maps repressing a TRIE

How can I create a Clojure zipper for a TRIE, represented by nested maps, were the keys are the letters.? Something like this: {\b {\a {\n {\a {\n {\a {'$ '$}}}}}} \a {\n {\a {'$ '$}}}} Represents a trie with 2 words 'banana' and 'ana'. (If…
0xMG
  • 93
  • 5
9
votes
4 answers

Parallel algorithm for constructing a trie?

Because the trie data structure has such a huge branching factor and each subtree is totally independent of the others, it seems like there ought to be a way to enormously speed up trie construction for a given dictionary by adding all the words in…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
8
votes
1 answer

MongoDB + Node.js + AJAX solution for doing autocomplete search

I'm looking to implement a typeahead/autocomplete search for fun. I have a few attributes within my schema in mongoDB, but I want to be able to search only by category, title, preview, or date. This is my mongoDB schema for a single article (I'm…
Benny Tjia
  • 4,853
  • 10
  • 39
  • 48
8
votes
3 answers

How do I create a fixed-length, mutable array of Python objects in Cython?

I need to have an array of python objects to be used in creating a trie datastructure. I need a structure that will be fixed-length like a tuple and mutable like a list. I don't want to use a list because I want to be able to ensure that the list…
Jason Baker
  • 192,085
  • 135
  • 376
  • 510