sahni2-3 - Data Structures & Algorithms Exam 2 Sample...

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

View Full Document Right Arrow Icon
Exam 2 Sample 3, 75 Minutes Notes: 1. Write your name, social security number, and section in which you want your exam returned on each sheet. 2. Begin the answer to each question on a new sheet. 1. [18] The classes MyBinaryTreeNode and MyBinaryTree are given below. Objects of type MyBinaryTree are linked binary trees. public class MyBinaryTreeNode { Object element; BinaryTreeNode leftChild; // left subtree BinaryTreeNode rightChild; // right subtree } public class MyBinaryTree { BinaryTreeNode root; // root node // code you write will come here } You are to write a public method maxHeightDifference() . The invocation x.maxHeightDifference() returns 0 if the binary tree x is empty; otherwise, it returns the maximum difference in the heights of the left and right subtrees of any node in the tree. x.maxHeightDifference() = max y is a node of x {|height(left subtree of y) - height(right
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

sahni2-3 - Data Structures & Algorithms Exam 2 Sample...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online