10303 - irritation in the problem statement
Moderator: Board moderators
10303 - irritation in the problem statement
the problem statement says, a binary search tree is a data structure, which can find a node in O(n log n). Of course this is a true statement (because of the O-symbol), but even with the worst case tree, one can find any node in O(n). If the tree is balanced it's even O(log n).
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: 10303 - irritation in the problem statement
lol, nice mistakepalmcron wrote:the problem statement says, a binary search tree is a data structure, which can find a node in O(n log n). Of course this is a true statement (because of the O-symbol), but even with the worst case tree, one can find any node in O(n). If the tree is balanced it's even O(log n).

-
- System administrator
- Posts: 1286
- Joined: Sat Oct 13, 2001 2:00 am
- Location: Valladolid, Spain
- Contact:
And depending on the leafs, it can be found in the first search. Anyway, as the description is talking about average time, I think that an average time for all possible trees is O(log n), and it looks like it's what the problemsetter meant.
I've changed the description. If i'm wrong (I'm not a data strcture expert) tell me. If there are no replies in one week I'll close the topic.
I've changed the description. If i'm wrong (I'm not a data strcture expert) tell me. If there are no replies in one week I'll close the topic.
DON'T PM ME --> For any doubt, suggestion or error reporting, please use the "Contact us" form in the web.
The current text is
A binary search tree is a binary tree with root k such that any node v reachable from its left has label (v) <label (k) and any node w reachable from its right has label (w) > label (k). It is a search structure which can find a node with label x in O(log n) average time, where n is the size of the tree (number of vertices).
I would suggest changing it to (changes are given in bold font)
A binary search tree is a binary tree with root k such that any node v in the left subtree of k has label (v) < label (k) and any node w in the right subtree of k has label (w) > label (k).
(When using binary search trees, one can easily look for a node with a given label x: After we compare x to the label of the root, either we found the node we seek or we know which subtree it is in. For most binary search trees the average time to find one of its n nodes in this way is O(log n).)
The rationale for the changes:
- The first new text is more correct than "reachable from its left" (and probably more clear too
)
- There are degenerate BSTs where the average time to find a node is linear in n. But in this problem we are supposed to count all BSTs, including the degenerate ones. The original formulation is slightly deceiving. That's why it's better to give it a separate paragraph and to put it into parentheses.
A binary search tree is a binary tree with root k such that any node v reachable from its left has label (v) <label (k) and any node w reachable from its right has label (w) > label (k). It is a search structure which can find a node with label x in O(log n) average time, where n is the size of the tree (number of vertices).
I would suggest changing it to (changes are given in bold font)
A binary search tree is a binary tree with root k such that any node v in the left subtree of k has label (v) < label (k) and any node w in the right subtree of k has label (w) > label (k).
(When using binary search trees, one can easily look for a node with a given label x: After we compare x to the label of the root, either we found the node we seek or we know which subtree it is in. For most binary search trees the average time to find one of its n nodes in this way is O(log n).)
The rationale for the changes:
- The first new text is more correct than "reachable from its left" (and probably more clear too

- There are degenerate BSTs where the average time to find a node is linear in n. But in this problem we are supposed to count all BSTs, including the degenerate ones. The original formulation is slightly deceiving. That's why it's better to give it a separate paragraph and to put it into parentheses.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm