Homework2Upload - 1. Write a non-recursive method to...

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

View Full Document Right Arrow Icon
1. Write a non-recursive method to perform an in-order tree traversal. Hint: There is an easy solution that uses a stack as an auxiliary data structure and a more complicated but elegant solution that uses no stack but assumes that two pointers can be tested for equality. public static void inorderTraversal (TreeNode node) { while (node.hasLeftChild) { node = node.left node.visit(). if (node.hasLeftChild)) then node = node.right while node.hasLeftChild { node = node.left(); } else { node = node.parent(); } } } 2. For the set of keys {1, 4, 5, 10, 16, 17, 21}, draw binary search trees of height 2, 3, 4, 5, and 6. 4 1 5 1 1 1 2 4 1 5 1 1 1 2 4 1 5 1 1 1 2 Height =  Height =  Height = 
Background image of page 1

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

View Full DocumentRight Arrow Icon
3. Create a node class for a tree whose nodes may have any number of children. This class must include both accessor and mutator methods for each data element of the class. public
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.

This note was uploaded on 04/07/2010 for the course CS CS1110 taught by Professor Ali during the Spring '10 term at Abu Dhabi University.

Page1 / 5

Homework2Upload - 1. Write a non-recursive method to...

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