SUNY Geneseo Department of Computer Science


Recursive Tree Algorithms

{Date}

CSci 141, Spring 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Example Tree Algorithm

Count the nodes in a tree:

    // In some subclass of OrderedTree...
    int count()
        if ( ! this.isEmpty() )
            int n = 1 + this.getLeft().count()
            return n + this.getRight().count()
        else
            return 0

Correctness?

Performance?

Next

Ordered Tree Properties

Read Section 13.3


Next Lecture