Question: Part 2 [ 6 0 marks ] - Binary Tree Traversals and extra operations. For this part of the assignment, you will be working with
Part marks Binary Tree Traversals and extra operations.
For this part of the assignment, you will be working with the BinaryTree class provided in the zip file. It contains four uncompleted functions that you are supposed to complete. For full marks, each of these functions should run in boldsymbolOboldsymboln time and must NOT use recursion. See the function traverse in BinaryTree.java that we also discussed in class for an example of how to do tree traversal without recursion. Note that this is just one example and there could be other functions that you may take inspiration from.
You need to implement the following operations:
The method leafCounter mode returns the following:
if mode it returns the number of left leaves.
if mode it returns the number of right leaves.
if mode it returns the total number of leaves in the tree.
The single root is a special case. Return regardless of the mode value.
Return if the tree has no nodes at all.
The method smallestLeaf should return the minimum depth in the tree that has leaves in it or if the tree has no nodes.
The method maxWidth should return the number of nodes in the most populated depth the depth with the largest number of nodes
The method treeCode should return a string that gives the stringencoded representation of the binary tree. The stringencoded representation of a binary tree can be defined as follows:
the encoded representation of a tree with no nodes is the string Obig O character
the encoded representation of a binary tree with root node r consists of an open bracket followed by the encoded representation of r left followed by the encoded representation of r right followed by a closing bracket
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
