Sunday, March 5, 2017

CLRS Exercise 12.2-2

12.2-2
Write recursive versions of TREE-MINIMUM and TREE-MAXIMUM.

Recursive version of TREE-MINIMUM:
TREE-MINIMUM-RECURSIVE(x)
        if x.left == NIL
                return x
        return TREE-MINIMUM-RECURSIVE(x.left)

Recursive version of TREE-MAXIMUM:
TREE-MAXIMUM-RECURSIVE(x)
        if x.right == NIL
                return x
        return TREE-MAXIMUM-RECURSIVE(x.right)

No comments: