COSC 2011 3.0 Fundamentals of Data Structures

Assignment 5

  1. Give a method numberOfLeafs(BinaryTree tree) which computes the number of leafs of the binary tree. Make use of the methods of this interface. These classes may be used for testing.
  2. Give a method hasMoreThanThreeChildren(SimpleTree tree) which determines if the tree (not necessarily a binary tree) has a node with more than three children. Make use of the methods of this interface. These classes may be used for testing.
  3. Give a method hasHeapOrderProperty(BinaryTree tree, Comparator comparator) which determines if the binary tree has the heap-order property: for every node other than the root, the element stored at the node is greater than or equal to the element stored at the node's parent. Use the comparator to compare the elements (for this assignment assume that these are simply Objects, not Items) stored at the nodes. Make use of the methods of this and this interface. These classes may be used for testing.