exam3-3soln

# Exam3-3soln - return getMinimum(node.left public E getMinimum Non-recursive if(root == null return null BTNode<E> current = root

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

1. a. n == 1 n + f(n-1) b. false false true pathExists(maze, row-1, col) || pathExists(maze, row, col-1) c. g(7) / \ / \ g(5) g(3) / \ / \ g(3) g(2) g(1) g(1) / \ / \ g(1) g(1) g(0) g(1) d. 6 e. (i) 6 (ii) 782 (iii) 98432 (iv) -6745231 2. a. 6 / \ 3 8 / \ / \ 1 5 7 9 b. O(n) O(n) O(n) O(n^2) c. 49 / \ / \ 34 88 / \ / 28 41 62 / \ 53 77 d. 43 or 61 / \ / \ 22 74 22 74 / \ / \ / \ / \ 10 32 61 80 10 43 72 80 \ / 72 32 e. ABDFGCEHI FDGBACHEI FGDBHIECA

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

View Full Document
3. a. 7, 3, 5 b. 10 18 26 32 22 63 54 or 26 18 10 32 22 54 63 c. 22 18 10 26 32 63 54 d. O(n) e. (i) insertion sort (ii) merge sort (iii) merge sort 4. public E getMinimum() { // Recursive if (root == null) return null; return getMinimum(root); } private E getMinimum(BTNode<E> node) { if (node.left == null) return node.data;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return getMinimum(node.left); } public E getMinimum { // Non-recursive if (root == null) return null; BTNode<E> current = root; while (current.left != null) { current = current.left; } return current.data; } 5. public boolean equals(BinaryTree<E> binTree) { if (binTree == null) return false; return equals(root, binTree.root); } private boolean equals(Node<E> root1, Node<E> root2) { if (root1 == null && root2 == null) return true; if (root1 == null || root2 == null) return false; return root1.data.equals(root2.data)) && equals( root1.left, root2.left) && equals( root1.right, root2.right); }...
View Full Document

## This document was uploaded on 12/19/2009.

### Page1 / 2

Exam3-3soln - return getMinimum(node.left public E getMinimum Non-recursive if(root == null return null BTNode<E> current = root

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

View Full Document
Ask a homework question - tutors are online