Number 1

Assuming a Node class

class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}

Write a method int numberLeaves(Node tree) that returns the number of leaves in the binary tree whose root is tree.

Number 2

Assuming a Node class

class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}

Write a method int size(Node tree) that returns the number of nodes in the binary tree whose root is tree.

int size(Node tree) {
if(tree == null) {
return 0;
}

return 1 + size(tree.left) + size(tree.right);
}

Number 3

Add the following new method in the BST class.

/** Returns the number of nodes in this binary tree */
public int getNumberOfNodes()

Requirements:

  • Dont use return size;
  • Write a recursive method that returns the number of nodes starting from the root.

Number 4

  • Create a constructor(last name, first name, office number)
  • Create a set method to set all class fields
  • Create a toString method
  • Create a copy constructor:-

* Copy constructor is defined by some authors as simply a constructor that accepts an object of the same class as an argument.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.