0

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.

2
  • why do you have an unbalanced/unordered tree? surely the point of a binary tree is for really fast searches. Commented Feb 23, 2012 at 20:13
  • What have you done so far? Do you have any code you can show us to show what you tried? Commented Feb 23, 2012 at 20:15

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.