Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binary tree very slow!
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00057594
Message ID:
00057636
Views:
25
>Hi
>
>I have implemented a binary tree in a table using at least the following three fields: id, left and right where id is the node identification and left and right are children of the node. Each child can point to another node id of the same table using its identification number. I used 0 when there is no child.
>
>I Created a class to iterate on that three using postfix search but it is not very performant. For a tree that has only 64 nodes, it takes about 5 seconds to do only a postfix search for each node without doing any piece of code during the search. A GOTO statement is used each time a child must be visited resulting of a lots of disk access. I know that the search time must increase as the tree growth but I can't live with a very poor performance like that.
>
>Is there a way to improve performance significantly using my tree implementation ?
>
>Is there any other way faster to implement a tree in a data base environment ?
>
>thanks in advance

Francois,

Admittedly, I haven't fooled with binary trees in about 10 years, so if its implementation has changed, I'll trust that you'll forgive me.

I've read and re-read this posting several times, and my problem isn't in understanding what you're trying to do, but rather why you're trying to do it this way. In order to properly search a tree, there must be a member or members to be searched. The thing I keep coming back to is: Why not just create a index on the field(s) and seek the value you need?

My gut feeling on this (and I may be way off base) this that you're try to establish some sort of hierarchy (the use of the word children). If this is the case, then my reaction would be that you're not using the b-tree correctly, since the purpose of the structure is to produced an organized (from least to greatest) list or structure.

At any rate, any attempt to locate a value in an organized list, such as a b-tree or sorted array, should require the exmaination of no more than Log2(n + 1) elements. In this case, with 64 nodes, that would mean 7 of them. If this is taking 5 seconds, somethings very wrong.

hth,

George
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform