SUNY Geneseo Department of Computer Science


Tree Traversals, Part 2

{Date}

CSci 240, Spring 2007
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture

Misc

SOFIs

Lab 11 (tree height) due today

Questions?

Tree Traversals

Process (e.g., print) all nodes in a tree

    // In class BinaryTree<E>
    private E root
    private BinaryTree<E> left, right

    traverse() {
        if ( ! this.isEmpty() ) {
            left.traverse()                   n1 elements
            process root                      constant time
            right.traverse()                  n2 elements
        }
    }

Kinds of traversal

Section 13.3.2

Can you do a more rigorous derivation of execution time?

Uses of traversals

Lab

Hand out Lab 12

Dictionary data structure

Next

Priority queues and heaps

Read...


Next Lecture