I have to code a TriesConstruct and also a TriesDestruct, how do I do this using that implementation?
Is tries a good data structure to store sorted or unsorted dictionaries
Main Topics
Browse All Topicscan anyone here help me to find an implementation of a tries in C? if possible the .h and .c file..
the tries is to store words in a dictionary and it needs to be able to have a insert function and a lookup function to see if a particular word exists or not
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> but it's kind of slow
What is slow ? And how did you measure/compare it ?
>> I have to code a TriesConstruct and also a TriesDestruct, how do I do this using that implementation?
The implementation of the trie I posted looks pretty complete, including the functions you mentioned. Did you look at the source code ?
oh yes it has the tries construct and tries destruct that I need.. however how do I traverse this tries in order??
slow here I compare it using the time feature in unix.. I am supposed to reach a particular time but my current implementation is far beyond.. say it's supposed to be 6 sec to store a words but my implementation takes 1 minute
>> but my implementation takes 1 minute
??? 1 minute to store a word in a data structure ? You've got a serious problem lol.
>> however how do I traverse this tries in order??
A trie is not made to traverse it - it's made for performing lookups (reTRIEvals). That said, you can always traverse it by going over every level of the trie in order.
I see.. so it's kind of hard to traverse a trie..lol.. Is a trie better than a hash table?
>>??? 1 minute to store a word in a data structure ? You've got a serious problem lol.
that's why I am asking here.. I must store the data in somekind of a data structure and then be able to have an iterator that will go rhrough all the data in a sorted order.. right now I am using a threaded BST which is easy to traverse using an iterator and it doesn't have to be recursive
I was thinking of just storing all the data in an array and then do a quick sort on that array then do an iterator on that array that is sorted.. but I am just wondering if this is faster than my current threaded BST
>> so it's kind of hard to traverse a trie
It's not hard (just traverse every level of the trie in order) ... It's just not something that is generally done with a trie.
>> I must store the data in somekind of a data structure and then be able to have an iterator that will go rhrough all the data in a sorted order..
You already have it sorted, so why not just store it in an array ?
>> a threaded BST
A threaded BST ? What do you mean ?
Thanks for that link, Paul. That clarifies quite a lot, and contains important information that kinghalls failed to mention in this post :)
If the problem is to combine two files (one big sorted file, and a smaller unsorted file) into one sorted file, then I would simply sort the unsorted file, and then merge both files into the output file (which will also be sorted as a consequence).
Anyway, I think your original question about trie implementations was answered, correct ? So, all questions regarding what is the most optimal approach for this should go in your other thread (the one Paul posted a link for), because that's the subject of that other question.
I agree I08 but this question is valid and valuable. Use of a trie in this case may produce a near-optimal solution. Many programmers seem to think that there are only three main storage data structures; lists, trees and hashmaps. :(
kinghalls, please try to give as much information as possible about your question, especially with links to related threads. You also need to do some coding. We can fix your problems and guide you in what you want to do but sadly we cannot do it for you.
Paul
Hi I08,
My reading of the question I linked to suggests that this is an assignment to demonstrate the benefits of optimal algorithms and data structures.
They are given one sorted dictionary (potentially large) and one unsorted list of words. They are asked to generate a sorted list of those words that appear in both files.
They must adhere to an interface that looks workable.
Paul
>>They are given one sorted dictionary (potentially large) and one unsorted list of words. They are asked to >>generate a sorted list of those words that appear in both files.
this is true, however it is not always the case that one is larger and one is smaller.. in one of the test cases.. it takes two similar files which is the same (same words, and of course same size). the first file I read into a hash table (I don't care of the ordering because the purpose of storing this into a hash table is for better lookup). As for the second time, when I read the same file.. I do a hash table lookup to see if that elements exists in the hash table AND I also have to do a lookup in my array to see if it already exists there.. if it exists in the hash table but does not exist in the array then I do an insertion.
After I insert all the words into an array. I will have to be able to traverse them in sorted order (if not it wouldn't be a dictionary). So for the second file, I will need a data structure that needs to be traversed.. As Infinity said a trie is not usual to be traversed. So what would a great data structure here? I am sure for reading the first file choosing a hash table is a correct choice as it only server the purpose for a lookup, which can be done in O(1)...
Infinity08
yes that would be a great idea, but I can't do this as there are some parts of the code that I can't change and it is the steps doing this. The steps MUST be:
1. for each word in the first file, put word into a structure until all the words have been traversed i
2. for each word in the second file, check if it exists in the first file, if not then check if it exists in the
current data structure.. if both satisfies then put it into the structure.
3. traverse the second structure and then write the words into a new file in sorted order.
those three steps COULD NOT be change whatever happens..
so what now?
Big O notation doesn't tell you everything :
1) a hash table has quite a bit of overhead calculating the hashes
2) a hash table can have collisions
3) the data in a hash table is not ordered
4) the operations on a trie are very fast on pretty much all platforms (simple array indexing)
You'll have to test and see which of the two is faster :)
But I'm sure this has already been covered in your other question.
Business Accounts
Answer for Membership
by: Infinity08Posted on 2008-05-04 at 10:36:03ID: 21496314
Simple Google search :
fi dBFAF39CE5 9474A43252 8082EC0FD1 3B397EE4CD A.aspx
http://www.koders.com/c/