Question 12.1.2: Write a procedure that checks if an element t : Tis present......

Write a procedure that checks if an element t : Tis present in an ordered tree (as described above).

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.
if root = null then begin

..t is not in the tree

end else begin

x := root ;
{invariant:  it remains to check if t is present in
a nonempty subtree rooted at x}
while  ((t < val [x]) and (left  [x] <> null)) or
((t > val [x]) and (right  [x] <> null)) do begin

if t < val [x] then begin {left  [x] <> null}

I x := left [x];

end else begin {t > val [x], right  [x] <> null}

x := right  [x];

end;

end;
{either t = val [x] or t is not in the tree}
..answer is (t = val [x])

end;

Related Answered Questions

Question: 12.2.2

Verified Answer:

By induction over n, we prove that Φ_{n+2} ...
Question: 12.2.1

Verified Answer:

The maximal number of vertices is equal to ...
Question: 12.1.3

Verified Answer:

val [null]  := t; x := root ; while t <> val...