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
7
votes
4 answers

Is a Trie a K-ary tree?

If you look at the node definitions for a simple Trie and a simple K-ary tree, they look the same. (using C++ notation) template trieNode { trieNode *[K] }; template KaryNode { KaryNode *[K] }; At its simplest a K-ary…
Glenn Teitelbaum
  • 10,108
  • 3
  • 36
  • 80
7
votes
5 answers

Trie Implementation With Map

i was working solving a problem today. But i got stucked. I know how a trie works but the problem is that i know how to implement it with static arrays and classes. Today surfing on the web i read that there is a way to implement tries using…
Giuseppe
  • 490
  • 1
  • 11
  • 27
7
votes
1 answer

Trie vs red-black tree: which is better in space and time?

Tries and red-black trees are very efficient for storing strings. Which has better time complexity? How about space complexity?
6
votes
0 answers

Stream variant of the Longest palindromic substring

Suppose I have a character stream as my input. What is the most optimal way to find the longest palindromic substring after each new character is added without reprocessing the whole string all over again? After each new character comes in, I…
user78706
6
votes
2 answers

A trie implementation in Delphi?

Anyone knows a ready-to-use trie [sic] implementation in Delphi? An optimized trie would be even better. Thanks in advance!
Mehdi
  • 1,075
  • 1
  • 11
  • 24
6
votes
1 answer

How to create, update and read a radix tree that won't fit into memory?

I’m interested in using a radix tree (or Patricia trie) to store a hash/dict/array of strings -> values. However, I'm finding that I have too many strings to fit into memory. I found an article by Algolia about how they solved this problem with…
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
6
votes
2 answers

Why are hash maps better than trie maps?

By trie map I mean an associative array, where the payloads are stored in a trie instead of a hash table. When I'm using a hash map/table, the keys I use are typically strings. What are the advantages of a hash map over some trie based map? I have…
Ramfjord
  • 872
  • 8
  • 14
6
votes
2 answers

Immutable Trie structure in F#

I am playing around with the aho-corasick algorithm to try and get a little better with F#, and I ran across a problem with the Trie implementations, they are all mutable or can't be tail call optimized. The basic issue from what I can see is that…
Snark
  • 1,664
  • 14
  • 27
6
votes
4 answers

what the author of nedtries means by "in-place"?

I. Just implemented a kind of bitwise trie (based on nedtries), but my code does lot Of memory allocation (for each node). Contrary to my implemetation, nedtries are claimed to be fast , among othet things, Because of their small number of memory…
fokenrute
  • 739
  • 6
  • 17
6
votes
1 answer

Trie implementation with wildcard values

I'm implementing an algorithm to do directory matching. So I'm given a set of valid paths that can include wildcards (denoted by "X"). Then when I pass in an input I need to know if that input matches with one of the paths in my valid set. I'm…
6
votes
2 answers

Scalable Trie implementation in PHP

Following this tutorial I met the Trie data structure. Since recently I've been programming in PHP I tried to solve the lecture's problem with that. I was able to achieve correct answers, but only for smaller inputs (Input #10 is a 2,82 MB file).…
csirmazbendeguz
  • 598
  • 4
  • 13
6
votes
1 answer

IPv6 lookup data structure

A patricia trie is the well-know, recommended data structure for storing IPv4 allocations/assignments and performing lookup. Is this true for IPv6 adddresses too? Just a deeper/taller trie to accommodate the extra 96 bits? Is the trie still…
SnickersAreMyFave
  • 5,047
  • 8
  • 26
  • 24
6
votes
1 answer

Php prefix tree implementation versus assoc array

UPD: I moved original question to https://codereview.stackexchange.com/questions/127055/building-tree-graph-from-dictionary-performance-issues Here is a short version, without codes. I'm trying to build a prefix tree from dictionary. So, using the…
haldagan
  • 911
  • 5
  • 16
6
votes
2 answers

How can I make my trie more efficient?

I'm working on a hacker rank problem and I believe my solution is correct. However, most of my test cases are being timed out. Could some one suggest how to improve the efficiency of my code? The important part of the code starts at the "Trie…
Luke Xu
  • 2,302
  • 3
  • 19
  • 43
6
votes
1 answer

Which data structure is most suitable to implement a Dictionary?

I have to write a Dictionary program as a semester project for an undergraduate course on Data Structures and Algorithms, and I am expected to find the most suitable solution (Data Structure) to the problem. I considered using either a hash table or…
Saif Khan
  • 309
  • 1
  • 2
  • 19