binary search tree method that visits all nodes with in range

Can someone help me figure which type of search this would be and how to implement it:
Write pseudocode for a binary search tree method that visits all nodes whose data lies within a given range of values beteewn 100 and 1,000
Consider the property of the BST
left_subtree < node < right_subtree

If the value in the node is in the range, its children may also be so you need to test both.
If the value lies outside of the range, you know that a whole subtree would also be outside, so you simply don't test it.
with the wording of this question we can assume that there are numbers out of that range which we need to ignore. right?
No, they may all fall in the range.
I am saying the tree may have numbers from 1 - 2,000 but we just ignore what is not in the range
If the value don't fall in the range you just don't visit it.
Then you may ignore a whole subtree, because you know that all their values will lie outside the range.
Maybe it would be easier to understand with a visual aid. Think about how to visit the nodes between 5 and 13 in this tree:

                 8
            /          \
       4                   12
     /    \              /    \
  2         6         10        14
 / \       / \       / \       /   \
1   3     5   7     9   11    13   15
Last edited on
I see so when we get 4 would never even go left because that is out of range. Totally understand. Thanks.
Also, what program did you make that tree on?
I just did it by hand.
Topic archived. No new replies allowed.