Reputation: 95
This is probably a simple task for expert coders, but is it possible to recursively traverse a binary unordered tree to find a node?
I can do this for a binary search tree, but I'm struggling with how to do this when the tree is unoredered since I can't figure out how to traverse back up when a node is not found in a branch...
C++ would he helpful.
Thanks guys.
Upvotes: 0
Views: 579
Reputation: 8278
use iteration. pseudo code below:
ITERATIVE-TREE-SEARCH(x, k)
while x ≠ NIL and k ≠ key[x]
do if k < key[x]
then x ← left[x]
else x ← right[x]
return x
Upvotes: 1