Skip to main content
added 6 characters in body
Source Link
vnp
  • 58.7k
  • 4
  • 55
  • 144

You are allocating a lot of space (and much of it is wasted). Grabbing memory affects performance in various ways, most important being a cache performance. And with the links pointing all over the memory space, cache misses incur serious cost over tree traversal.

Bottomline is, do not expect a good performance from a tree with high branghing factor. Take a look at a PATRICIA (or radix) tree for a correct implementation of your idea.

PS: My two cents in addition to @syb0rg analysis: using fseek restricts you from the streaming files, and strictly speaking it is not necessary at all:

while((c = fgetc(dict)) != EOF) {
    current = root; //set index to root

    for(; c != '\n'; c = fgetc(dict)) //iterate through word
    {
        ...
    }

You are allocating a lot of space (and much of it is wasted). Grabbing memory affects performance in various ways, most important being a cache performance. And with the links pointing all over the memory space, cache misses incur serious cost over tree traversal.

Bottomline is, do not expect a good performance from a tree with high branghing factor. Take a look at a PATRICIA (or radix) tree for a correct implementation of your idea.

PS: My two cents in addition to @syb0rg analysis: using fseek restricts you from the streaming files, and strictly speaking it is not necessary at all:

while(fgetc(dict) != EOF) {
    current = root; //set index to root

    for(; c != '\n'; c = fgetc(dict)) //iterate through word
    {
        ...
    }

You are allocating a lot of space (and much of it is wasted). Grabbing memory affects performance in various ways, most important being a cache performance. And with the links pointing all over the memory space, cache misses incur serious cost over tree traversal.

Bottomline is, do not expect a good performance from a tree with high branghing factor. Take a look at a PATRICIA (or radix) tree for a correct implementation of your idea.

PS: My two cents in addition to @syb0rg analysis: using fseek restricts you from the streaming files, and strictly speaking it is not necessary at all:

while((c = fgetc(dict)) != EOF) {
    current = root; //set index to root

    for(; c != '\n'; c = fgetc(dict)) //iterate through word
    {
        ...
    }
Source Link
vnp
  • 58.7k
  • 4
  • 55
  • 144

You are allocating a lot of space (and much of it is wasted). Grabbing memory affects performance in various ways, most important being a cache performance. And with the links pointing all over the memory space, cache misses incur serious cost over tree traversal.

Bottomline is, do not expect a good performance from a tree with high branghing factor. Take a look at a PATRICIA (or radix) tree for a correct implementation of your idea.

PS: My two cents in addition to @syb0rg analysis: using fseek restricts you from the streaming files, and strictly speaking it is not necessary at all:

while(fgetc(dict) != EOF) {
    current = root; //set index to root

    for(; c != '\n'; c = fgetc(dict)) //iterate through word
    {
        ...
    }