Josh Sebastian wrote:
[color=blue]
> On Sat, 04 Oct 2003 06:06:01 +0000, Ridimz wrote:
>[color=green]
>> I have implemented a binary search tree and am interested in displaying
>> all keys less than a certain value. I understand how to approach this
>> task if the searchValue is equal to root.key(). Otherwise I'm lost. Any
>> suggestions or examples would be greatly appreciated[/color]
>
> In a BST, all elements less than the current node's value are to
> the left. So keep moving down and to the left until you find the first
> node with a value less than you value, and display the values of all the
> nodes on the subtree with that node for the root.[/color]
(Please select a non-proportional font.)
Let's test that theory. I'm looking for anything less than H in the
following tree:
M
F R
D I P U
A E G J N Q T W
Your algorithm starts by going from M to F. F is less than H, so your
algorithm will display the values of all the nodes on the subtree with F at
the root. These are A, D, E, F, G, I, J.
Neither I nor J is < H. I conclude that the algorithm is flawed.
--
Richard Heathfield :
binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc:
http://users.powernet.co.uk/eton