Tutorial 8

Tutorial 8 - CS 134 Tutorial 8 Binary Trees CS 134 Tutors...

This preview shows pages 1–3. Sign up to view the full content.

CS 134 Tutorial 8: Binary Trees CS 134 Tutors Winter 2008 1 Recursive Methods 1.1 Average in a Non-Empty Binary Tree Write a recursive method inside the BinaryTree class that calculates the average in a non-empty binary tree of Integer s. Note that you may want to use a method size() , which returns the number of nodes in a binary tree. (You will have to implement this method since it is not part of the BinaryTreeInterface ). public class BinaryTree implements BinaryTreeInterface { // pre: this is a non-empty binary tree storing only Integer objects // post: returns the average of integer values stored in the tree rooted at this public double findAverage() { } // post: returns the number of nodes in this binary tree private int size() { } } 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Binary Tree Traversals 2.1 Four Ways to Get Around the Tree There are many methods used to visit all nodes in a binary tree. Diﬀerent methods are used depending on the programmer’s objectives. We discussed one iterative way of traversing a tree:
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

Tutorial 8 - CS 134 Tutorial 8 Binary Trees CS 134 Tutors...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online