trie

How Do I Choose Between a Hash Table and a Trie (Prefix Tree)?

So if I have to choose between a hash table or a prefix tree what are the discriminating factors that would lead me to choose one over the other. From my own naive point of view it seems as though using a trie has some extra overhead since it isn't stored as an array but that in terms of run time (assuming the longest key is the longest ...

What is the most common use of the "trie" data structure?

I want to learn more about "trie" data structures. I've read about them on Wikipedia but I'm still confused. What is the most common use? Auto-complete in the address bar of a web browser... or? Cheers! ...

Stuck on a Iterator Implementation of a Trie

Hello everyone, 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 <typename T> class Trie<T>::IteratorPrefixe{ friend class Trie<T>; public: IteratorPrefixe() ...

How do you store a trie in a relational database?

I have a prefix trie. What is the recommended schema for representing this structure in a relational database? I need substring matching to remain efficient. ...

Where do I find a standard Trie based map implementation in Java?

I have a Java program that stores a lot of mappings from Strings to various objects. Right now, my options are either to rely on hashing (via HashMap) or on binary searches (via TreeMap). I am wondering if there is an efficient and standard trie-based map implementation in a popular and quality collections library? I've written my own...

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 strings are in the set. By comparison, a balanced tree would be O(log N) in the number of s...

Trie Implementation Question

I'm implementing a trie for predictive text entry in VB.NET - basically autocompletion as far as the use of the trie is concerned. I've made my trie a recursive data structure based on the generic dictionary class. It's basically: class WordTree Inherits Dictionary(of Char, WordTree) Each letter in a word (all upper cased) is used a...

How to traverse a trie longitudinally?

Hello, i have a Trie and several functions modifiing it. typedef struct node *pnode; typedef struct node { int element; pnode next;//same level, other element pnode subtree;//next level } node; Now, in order to debug and/or test my functions, I need to print out the tries. I tried it recursively, but I cannot get the fi...

Trie (Prefix Tree) in Python

I don't know if this is the place to ask about algorithms. But let's see if I get any answers ... :) If anything is unclear I'm very happy to clarify things. I just implemented a Trie in python. However, one bit seemed to be more complicated than it ought to (as someone who loves simplicity). Perhaps someone has had a similar problem? ...

What's the best way to implement web service for ajax autocomplete

I'm implementing a "Google Suggest" like autocomplete feature for tag searching using jQuery's autocomplete. I need to provide a web service to jQuery giving it a list of suggestions based on what the user has typed. I see 2 ways of implementing the web service: 1) just store all the tags in a database and search the DB using user inp...

Trie implementation

Is there any speed- and cache-efficient implementations of trie in C/C++? I know what a trie is, but I don't want reinvent the wheel, implementing it myself. ...

Space-efficient in-memory structure for sorted text supporting prefix searches

I have a problem: I need space-efficient lookup of file-system data based of file path prefix. Prefix searching of sorted text, in other words. Use a trie, you say, and I thought the same thing. Trouble is, tries are not space-efficient enough, not without other tricks. I have a fair amount of data: about 450M in a plain-text Unix-for...

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 (15 ())) (20 (25 ())))))) ...

[c++ / pointers]: having objects A and B (B has vector member, which stores pointer to A), knowing A is it possible to retrieve pointer to B?

Hello, While trying to learn c++, I tried to implement class representing very basic trie. I came up with the following: class Trie { public: char data; vector<Trie* > children; Trie(char data); Trie* addChild(Trie* ch); // adds child node (skipped others members/methods) }; Method addChild checks if child c...

Which data structure to add/look up/keep count of strings?

I'm trying to figure out what data structure to quickly support the following operations: Add a string (if it's not there, add it, if it is there, increment a counter for the word) Count a given string (look up by string and then read the counter) I'm debating between a hash table or a trie. From my understanding a hash table is fast...

Optimizing word count

(This is rather hypothetical in nature as of right now, so I don't have too many details to offer.) I have a flat file of random (English) words, one on each line. I need to write an efficient program to count the number of occurrences of each word. The file is big (perhaps about 1GB), but I have plenty of RAM for everything. They're...

File backed Trie (or Prefix Tree) implementation

I have to store lot of strings in c++ map to keep unique strings and when ever duplicate string occurs I just need to increment the counter (pair.second). I've used c++ map and it well fits to this situation. Since the file that processing is gone now upto 30gig I am trying to keep this in a file instead of memory. I also came across ...

how to implement trie data structure using c for the identification of sets?

here we should write a program to implement the identification of sets(object sets containing strings not in an alphabetical order) which makes basically use of tries. ...

How to do fast prefix string matching in Scala

I'm using some Java code to do fast prefix lookups, using java.util.TreeSet, could I be using scala's TreeSet instead? Or a different solution? /** A class that uses a TreeSet to do fast prefix matching */ class PrefixMatcher { private val _set = new java.util.TreeSet[String] def add(s: String) = _set.add(s) def findMatches(pre...

Generate directory tree from large flat directory list

Let's say I have one directory in my filesystem, which has a number of subdirectories and files. The number of subdirectories and files in this directory runs to many tens of thousands. You'll be familiar with the significant delay you'll get in attempting to view the contents of this directory, even in a terminal. I've seen this solu...