Questions tagged [prefix-tree]

In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings

In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are normally not associated with every node, only with leaves and some inner nodes that correspond to keys of interest.

57 questions
0
votes
1 answer

Merge two binary trie

I want to merge two trie structures, but the best complexity I can think of is Get list of values from other trie: O(n), n is number of nodes in trie. Insert all values from list intro target trie: n * O(m), m is length of key Taking into account,…
ValentaTomas
  • 260
  • 3
  • 11
0
votes
1 answer

Insert and Search implementation in Prefix Tree

I am working on an implementation with prefix, where i am trying to construct the following F->R->E->T->(latitude + longitude) I have implemented the insert function and it seems to be working. I verify this by printing out the respective latitude…
RRP
  • 2,563
  • 6
  • 29
  • 52
0
votes
1 answer

How to generate Huffman prefix code?

I'm working on a c++ program and my group and I cannot figure out the logic on how to generate the prefix code using an inOrder traversal. We have the PrefixCode Tree built and we want to generate the codes from that. Since we are having issues…
ryandonohue
  • 189
  • 4
  • 22
0
votes
1 answer

Manipulating trie implementation to get the found items in an array

I found this trie implementation from Code Review, it works perfectly, I already changed it somehow to fit my program's needs now I want to manipulate the find() function so I can have the results in an array. Thanks. Here's the class code: import…
RedHood148
  • 429
  • 2
  • 4
  • 14
0
votes
2 answers

Fetch Words Starting/Containing/Ending With Fragment in a Word Dictionary

Assuming that we have a list of all dictionary words from A-Z from the English dictionary. I have three cases to perform on these list of words: 1) find out all the words that are "starting with" a particular fragment eg: If my fragment is 'car',…
D3XT3R
  • 181
  • 2
  • 15
0
votes
1 answer

what the data structure for this?

i was given a set(no duplication then) of binary strings with arbitrary lenght and number, and need to find out if there is any string is the prefix of other string. for small set and string with small length, it's easy, just build a binary tree by…
ohana
  • 51
  • 1
  • 3
0
votes
1 answer

Performance issue while getting all the words with common prefix in Prefix Tree

I have a prefix tree to store a huge collection of words. Right now, if i want to find all the words with the common prefix say "a", I first retrieve the first node containing a and then exhaustively search in the Depth First fashion in the children…
consumer
  • 709
  • 3
  • 7
  • 19
0
votes
1 answer

Variable length codes

Suppose we have been given that our prefix-free binary code has 11 codewords of length 4, and 2 codewords of length 2. We are asked to come up with an example for it, but how can we make 11 codewords when the code length is 4 and we can only use 1s…
user65165
  • 874
  • 1
  • 8
  • 11
0
votes
1 answer

What's the lookup cost in prefix tree and why?

Given an prefix tree and a key. What's the cost of looking up the key in the tree? I read in a paper that it's O(1). As far as I know it's O(LogM) where M is the length of the key. I couldn't find an answer to this as why it's O(1) but one…
Jack Twain
  • 6,273
  • 15
  • 67
  • 107
0
votes
2 answers

DFS over string trie (prefix)

I wrote the following prefix trie: class TrieNode { char letter; HashMap children; boolean fullWord; TrieNode(char letter) { this.letter = letter; children = new HashMap(); …
Dejell
  • 13,947
  • 40
  • 146
  • 229
-1
votes
3 answers

What is the efficient way to search trough NSArray

I have NSStrings in my array: i[0] = axxx i[1] = axyz i[2] = axxy i[3] = abcd I want to pass a search string to find all needed strings. For example if I pass "ax" then it will return 3 strings, if I pass "axx" then it will return 2…
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
-2
votes
1 answer

Recursive function gives segmentation fault, how to point a pointer object to it's child?

So I have a prefixtree object that has multiple nodes. Each node consists of a character, whether it is a final node, and it's children stored in an object pointer array (up to 26 values). I need to print the words found beneath a given node.…
kingk
  • 11
  • 5
1 2 3
4