algorithm - Binary tree recursive problem -


I found this problem and I'm not completely sure that my approach is correct:

"A binary tree can be encoded using two functions L and R, such as node n, L (n) left child n (or zero if none) and R (n) gives the right child (Or zero if none). Test (L, R, X) Root node for binary tree with encoding from L and R functions with x To make a simple recursive algorithm for taking binary trees, and "yes", no node in the tree is not exactly a child, give the pseudocode for this algorithm. "

I Tried to do this:

  test (l, r, x) if ((L (x)! = Null & amp; r (x)! = Null) || (L ( X) = "null and r (x) == faucet") "yes" other ("L, R, L (X)" test (L, R, L (X)) == "Yes" test ("L "X") == "Yes" test (L, R, R) and "No" returns "Yes" return   

Is that correct? If L and R functions are there, why is the function passed as a normal parameter?

Thank you in advance for your reply!

The first thing you do is either yes or no return, so the final part is accessible is not.

I will change it so that you do not return a child, you do not return, otherwise you will not return to your children if you meet the criteria.

  Exam (L, R, X) if ((L (X)! = Null & amp;; Amp; R (x) == faucet) || (L (X) Return to "No" if (L (x) == faucet & amp;; r (x) == faucet) "Yes" return test (L, R, L (x) & amp; Amp; Test (L, r, x)    

Comments