Question

implementation of a tries?

Asked by: kinghalls

can 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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-05-04 at 10:29:46ID23375059
Topics

C Programming Language

,

Programming Languages

,

Algorithms

Participating Experts
2
Points
125
Comments
57

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. lookup
    i have situation in which i have to show a lookup field in a form .if i am using a TDBLookUpCombobox I am facing a situation where in the view i am not able to restrict the view of look up records other than the keyone .but during the insert mode i have to show all the record...
  2. About Dictionary
    Hi all I'm trying to write a English - Chinese dictionary program but I don't know how to do. Please tell me how to do such as how to include chinese fonts, how to lookup fonts,... Thanks you verry much P/S: I can work with VC,VB, .net
  3. List vs ArrayList, Dictionary vs Hashtable
    Hi !! The use of: List<string> stringList ... ... string test = stringList[0]; is easier code to write than: ArrayList stringList ... ... string test = (string)stringList[0]; The same goes for Dictionary<string, MyObject> vs Hashtable. BUT, question: which i...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: Infinity08Posted on 2008-05-04 at 10:36:03ID: 21496314

 

by: kinghallsPosted on 2008-05-04 at 10:51:43ID: 21496361

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

 

by: Infinity08Posted on 2008-05-04 at 10:54:05ID: 21496369

Ok, what's this about ... Are you sure you want a trie ? Do you need to develop this yourself ?

 

by: kinghallsPosted on 2008-05-04 at 10:55:34ID: 21496373

I am reading a sorted list of words and I wan't to take words by words from that line and put it into a tries data structure. Right now I am using a bst to store it, but it's kind of slow.. I was hoping that I can get improvements by changing the data structure into a tries.. any opinions?

 

by: Infinity08Posted on 2008-05-04 at 11:04:58ID: 21496393

>> 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 ?

 

by: kinghallsPosted on 2008-05-04 at 11:07:27ID: 21496401

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

 

by: Infinity08Posted on 2008-05-04 at 11:12:30ID: 21496418

>> 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.

 

by: kinghallsPosted on 2008-05-04 at 11:16:28ID: 21496433

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

 

by: kinghallsPosted on 2008-05-04 at 11:18:13ID: 21496439

or can you suggest me an idea how to improve this?

 

by: Infinity08Posted on 2008-05-04 at 11:19:08ID: 21496444

>> 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 ?

 

by: kinghallsPosted on 2008-05-04 at 11:23:10ID: 21496456

no not really actually.. what I am saying is that I have a data and I need to store it in order

 

by: Infinity08Posted on 2008-05-04 at 11:28:41ID: 21496484

>> no not really actually..

What was that a response to ?


>> what I am saying is that I have a data and I need to store it in order

If that's all you want to do, then a simple array is more than sufficient.

 

by: kinghallsPosted on 2008-05-04 at 11:30:36ID: 21496496

yes.. so I am guessing an array would do the work.. to make it more clear.. I am given a list of words and it can be sorted or not.. then I have to iterate over that file in a sorted fashion way.. so you think using an array and do a quicksort on it is good?

 

by: Infinity08Posted on 2008-05-04 at 11:39:30ID: 21496536

>> so you think using an array and do a quicksort on it is good?

If the whole array is not too large (will fit nicely in memory), then an array is a good solution.

 

by: kinghallsPosted on 2008-05-04 at 11:41:47ID: 21496549

I am storing like 5000 words into an array.. is that too big?

 

by: Infinity08Posted on 2008-05-04 at 11:43:42ID: 21496557

Nope. That sounds reasonable.

 

by: kinghallsPosted on 2008-05-04 at 11:47:11ID: 21496571

okay then.. I am going to build an ArrayList to do this.. it's supposed to be very easy just use a dynamic memory allocation whenever I want to insert right?

 

by: Infinity08Posted on 2008-05-04 at 11:49:23ID: 21496578

>> an ArrayList

an ArrayList ?

>> a dynamic memory allocation whenever I want to insert right?

Why ?


Why not use a simple array ?

 

by: kinghallsPosted on 2008-05-04 at 11:51:29ID: 21496585

okay then just use an simple array I guess..

but I don't know the size of the array as I don't know how big the size of the list is

 

by: Infinity08Posted on 2008-05-04 at 11:55:42ID: 21496597

>> as I don't know how big the size of the list is

Then find out the size first :)

 

by: kinghallsPosted on 2008-05-04 at 11:59:19ID: 21496610

then that doesn't make sense as I have to traverse the list of files first and then I know the size and then traverse it back again to get the words.. can I grow the array size dynamically?

 

by: Infinity08Posted on 2008-05-04 at 12:03:28ID: 21496620

>> the list of files

That's the first thing I hear of multiple files ;)


>> can I grow the array size dynamically?

Sure. But I wouldn't do that 1 by one ... Choose an intial size that is "a good guess", and if needed, increase the size by "a fair amount".

 

by: kinghallsPosted on 2008-05-04 at 12:20:22ID: 21496665

okay then.. how do I specify an array of words with a specific size?

 

by: Infinity08Posted on 2008-05-04 at 12:32:24ID: 21496693

>> how do I specify an array of words with a specific size?

Just :

char **words = new char*[size];

                                              
1:

Select allOpen in new window

 

by: kinghallsPosted on 2008-05-04 at 12:45:21ID: 21496725

could you please correct my code below, I know there's something wrong.

struct list_el {
  char** head;
  int index;
};
 
typedef struct list_el ArrayList;
 
 
ArrayList* ArrayListConstruct()
{
  ArrayList* this = (ArrayList*)malloc(sizeof(ArrayList));
  this->head = new char*[500];
  this->index = 0;
  return this;
}
 
void ArrayListDestruct(ArrayList* list)
{
  int ii;
  for (ii =0; ii<list->index; ii++){
    StringDestruct(list->head[ii]);
  }
 
  free(list);
}
 
boolean ArrayListInsert(ArrayList* this, char* data)
{
  if (this->index == 500){
    this->head  = realloc(this->head, sizeof(char *) * (this->index + 1));
    bld[bldIndex] = malloc(strlen(pc) + 1);
  }else if{
   this->head[(this->index) + 1] = data;
   this->index = this->index++;
  }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: Infinity08Posted on 2008-05-04 at 12:54:58ID: 21496750

define "something wrong"

 

by: kinghallsPosted on 2008-05-04 at 13:02:21ID: 21496773

I am not sure on the insertion if that's how I do it using dynamic memory allocation

 

by: kinghallsPosted on 2008-05-04 at 13:03:46ID: 21496776

and can you actually do

char **words = new char*[size];

this in C?

 

by: Infinity08Posted on 2008-05-04 at 14:00:32ID: 21496913

>> I am not sure on the insertion if that's how I do it using dynamic memory allocation

Just add it to the end of the array ... Your data is either already sorted or will be sorted after filling the array.


>> and can you actually do

No ;) Sorry :

char **words = (char**) calloc(size, sizeof(char*));

                                              
1:

Select allOpen in new window

 

by: kinghallsPosted on 2008-05-04 at 14:19:23ID: 21496964

and here's my last version of my code which still doesn't work when I try to traverse it

can you help me here

#include "list.h"
 
 
int main(){
 
  ArrayList* ar = ArrayListConstruct();
  ArrayListInsert(ar, StringConstruct("haha"));
  ArrayListInsert(ar, StringConstruct("my"));
  ArrayListInsert(ar, StringConstruct("name"));
  ArrayListInsert(ar, StringConstruct("is"));
  ArrayListInsert(ar, StringConstruct("aditya"));
  ArrayListTraverse(ar);
 
 
  return 0;
 
}
 
 
 
 
 
 
 
 
#include "cstr.h"
#include <stdlib.h>
#include <string.h>
 
int_u4 StringHash (const char* key)
{
  int_u4 h = 0;
  if (key!=NULL) {
    for (; *key; key++) {
      h = (h<<3) + ((*key)*(9781623));
    }
  }
  return h;
}
 
char* StringConstruct (const char* s)
{
  char* copy = (char*)malloc(strlen(s)+1);
  strcpy(copy, s);
  return copy;
}
 
void StringDestruct (char* s)
{
  if (s!=0) 
    free(s);
}
 
 
ArrayList* ArrayListConstruct()
{
  ArrayList* this = (ArrayList*)malloc(sizeof(ArrayList));
  this->head = (char**) calloc(500, sizeof(char*));
  this->size = 500;
  this->index = 0;
  return this;
}
 
void ArrayListDestruct(ArrayList* list)
{
  int ii;
  for (ii =0; ii<list->index; ii++){
    StringDestruct(list->head[ii]);
  }
 
  free(list);
}
 
boolean ArrayListInsert(ArrayList* this, char* data)
{
  if (this->index == this->size){
    this->head  = realloc(this->head, sizeof(char *) * (this->index + 1));
    this->index = (this->index)+1;
    this->head[this->index] = data;
    this->size = (this->size)+1;
    return true;
  }else {
   this->head[(this->index) + 1] = data;
   this->index = this->index++;
   return true;
  }
  return false;
}
 
int ArrayListLookup(ArrayList* this, char* data)
{
  return 1;
}
 
void ArrayListTraverse(ArrayList* list)
{
 int ii;
 for (ii = 0; ii<list->index; ii++){
   printf("%s\n", list->head[ii]);
 }
}
 
int compareStrings(const void* p1, const void* p2)
{
  char** s1 = (char**)p1;
  char** s2 = (char**)p2;
  if (strcmp(*s1, *s2)>0){
    return true;
  } else
    return false;
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:

Select allOpen in new window

 

by: Infinity08Posted on 2008-05-04 at 14:26:22ID: 21496981

What's ArrayList ?


You forgot to free(this->head); in ArrayListDestruct.


In your ArrayListInsert, you have to be aware that indexing starts at 0, so (this->index == this->size) is not necessarily what you think it is.

 

by: kinghallsPosted on 2008-05-04 at 15:01:27ID: 21497102

>>You forgot to free(this->head); in ArrayListDestruct.


>>In your ArrayListInsert, you have to be aware that indexing starts at 0, so (this->index == this->size) is >>not necessarily what you think it is.

   I just fixed those two problems...

ArrayList is this:


So besides all that it should work right?

struct list_el {
  char** head;
  int index;
  int size;
};
 
typedef struct list_el ArrayList;

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: Infinity08Posted on 2008-05-04 at 15:03:26ID: 21497108

>> So besides all that it should work right?

Test it ;) I just pointed out a few problems I immediately noticed. I might have missed something ... that's what testing is for :)

 

by: kinghallsPosted on 2008-05-04 at 15:07:34ID: 21497117

okay..I'll do some test now

 

by: kinghallsPosted on 2008-05-04 at 16:16:27ID: 21497328

I've got a problem.. why doesn't this work??

it always generates a seg fault

void ArrayListTraverse(ArrayList* list)
{
 qsort(list, list->index, sizeof(char*), compareStrings);
 int ii;
 for (ii = 0; ii<list->index; ii++){
   printf("%s\n", temp->head[ii]);
 }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: kinghallsPosted on 2008-05-04 at 16:44:49ID: 21497419

I fixed the problem above, now I have this problem:

that's a code fragment for the insert part... I think just doesn't do it right

 if (this->index == this->size){
    this->head  = realloc(this->head, sizeof(char *) * (this->index + 1));
    this->index = (this->index)+1;
    this->head[this->index] = data;
    this->size = (this->size)+1;
    return true;
  }

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: Infinity08Posted on 2008-05-05 at 01:59:28ID: 21498783

Did you fix this remark I made earlier ?

>> In your ArrayListInsert, you have to be aware that indexing starts at 0, so (this->index == this->size) is not necessarily what you think it is.

 

by: Infinity08Posted on 2008-05-05 at 03:31:43ID: 21498994

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.

 

by: PaulCaswellPosted on 2008-05-05 at 04:12:11ID: 21499100

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

 

by: Infinity08Posted on 2008-05-05 at 04:22:27ID: 21499143

I'd like to know if my understanding of the problem is correct : "If the problem is to combine two files (one big sorted file, and a smaller unsorted file) into one sorted file".

 

by: PaulCaswellPosted on 2008-05-05 at 04:31:52ID: 21499163

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

 

by: Infinity08Posted on 2008-05-05 at 04:36:26ID: 21499182

>> that appear in both files

That's the part I missed :) Ignore my suggestions for an array then :)

 

by: kinghallsPosted on 2008-05-05 at 06:33:17ID: 21499858

>>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)...

 

by: Infinity08Posted on 2008-05-05 at 06:39:11ID: 21499899

Just another idea maybe is to sort the second file, and then iterate over both files just once, retaining only the duplicates. No data structure overhead (except for the sorting phase). Might be worth testing for speed.

 

by: kinghallsPosted on 2008-05-05 at 07:05:05ID: 21500107

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?

 

by: Infinity08Posted on 2008-05-05 at 07:10:37ID: 21500138

>> so what now?

Follow the advice given in your other question ;) That's what that question was about :) This question is about tries.

 

by: kinghallsPosted on 2008-05-05 at 07:12:09ID: 21500153

>>Follow the advice given in your other question ;) That's what that question was about :) This question is >>about tries.

Just one more thing, so do you think using a tries will be a good idea?

 

by: Infinity08Posted on 2008-05-05 at 07:17:23ID: 21500177

>> so do you think using a tries will be a good idea?

Ye, why not ? It's perfectly fine for performing fast lookups. Don't doubt Paul ;)

 

by: kinghallsPosted on 2008-05-05 at 07:18:48ID: 21500187

but a hash table does a similar thing.. right? O(1) lookups?

 

by: Infinity08Posted on 2008-05-05 at 07:29:33ID: 21500265

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.

 

by: kinghallsPosted on 2008-05-05 at 07:30:49ID: 21500277

yes.. I understand all that, but we don't need ordered elements in the first structure, we only need to do a simple lookup

 

by: Infinity08Posted on 2008-05-05 at 07:37:59ID: 21500337

So, what's your point ?

 

by: kinghallsPosted on 2008-05-05 at 07:50:13ID: 21500431

so I am confident that hash table is enough

 

by: Infinity08Posted on 2008-05-05 at 07:52:17ID: 21500442

It's nice to be confident. But did you read all 4 points in my previous code ? I wouldn't be so confident, and I'd at least test out both approaches to see which one is faster.

 

by: kinghallsPosted on 2008-05-05 at 08:00:49ID: 21500511

yes.. I just tweak my code so that my hash table size would be larger and now it's got the speed I have

 

by: Infinity08Posted on 2008-05-06 at 07:04:49ID: 21507359

May I ask why you gave a B grade ? That usually means that something was missing in the answers and/or that something is still unclear. If so, you don't have to close the question, and you can feel free to ask for clarification.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...