Tutorial 8

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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. Different methods are used depending on the programmer’s objectives. We discussed one iterative way of traversing a tree:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online