C SC 205 Lecture 13: Trees and Binary Trees
major resources: Data Structures and the Java Collections Framework Second Edition, William Collins, McGraw-Hill, 2005
Introduction to Programming and OO Design using Java, Niño and Hosch, Wiley & Sons, 2002

[ previous | schedule | next ]

Wednesday October 31 (week 8)

Introduction and Trees in General

Introduction to Binary Trees

Binary Tree Terminology

Binary Tree Specification deferred for now

A cool array-based implementation for Binary Trees

A Linked Implementation of a Binary Tree

Traversing a Binary Tree

Binary Tree Example: arithmetic expressions

Arithmetic expressions can be stored very nicely in a binary tree. Such trees have the property that all leaf nodes represent operands and all non-leaf nodes represent operators. Assuming only binary operators, an operator's left operand will be contained in its left child and its right operand will be contained in its right child. Here's an example:

This tree represents the expression "2 * (3 + 4)". Notice that the tree did not need to store parentheses -- the right child of the "*", which is the result of the "+", has to be evaluated before the "*" can be evaluated.

Notice this also: Suppose you perform a pre-order traversal of this tree and print the value stored at each visited node. What is the output? Suppose you do the same thing with a post-order traversal?


[ C SC 205 | Peter Sanderson | Math Sciences server  | Math Sciences home page | Otterbein ]

Last updated:
Peter Sanderson (PSanderson@otterbein.edu)