(Depth of a Binary Tree ) modify the tree class provides a method getDepth that determines how many levels are in the tree. Test the method in an application that inserts 20 random integers into a treee.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct node
{
int data;
struct node *left;
struct node *right;
};
struct node *newNode(int data)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->data = data;
temp->left = temp->right = NULL;
return temp;
}
int Max_depth(node *node)
{
if (node == NULL)
// NULL means that no node is present
return 0;
else
{
// compute maximum height in left- subtree
int l = Max_depth(node->left);
// compute the depth of the right sub tree
int r = Max_depth(node->right);
if (r > l)
return(r + 1);
else return(l + 1);
}
}
int main()
{
struct node *root=NULL;
root = newNode(10);
root->left = newNode(20);
root->right = newNode(30);
root->left->left = newNode(40);
root->right->left = newNode(50);
root->left->right = newNode(90);
root->right->right = newNode(30);
root->right->right->left = newNode(88);
int level = Max_depth(root);
printf( "The maximum level of the tree is: %d " , level );
return 0;
}

(Depth of a Binary Tree ) modify the tree class provides a method getDepth that determines...
IN JAVA
2 A Binary Search Tree The goal of this lab is to gain familiarity with simple binary search trees. 1. Begin this lab by implementing a simple class that represents a "node” in a binary search tree, as follows. public class MyTreeNode<t extends Comparable<T>> { public T data; public MyTreeNode<T> leftchild; public MyTreeNode<T> rightChild; public MyTreeNode<T> parent; 2. Have the second member of your pair type in the code for the simple binary search tree interface. public interface...
Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary search tree in order. Description For the template class BinarySearchTree, fill in the following methods: insert - Inserts values greater than the parent to the right, and values lesser than the parent to the left.parameters elem - The new element to be inserted into the tree. printInOrder - Prints the values stored in the tree in ascending order. Hint: Use a recursive method to...
Program in JAVA: A Perfect binary tree is a complete binary tree with all levels fully filled. Add a method in the BST class to return true if the tree is a perfect binary tree.(Hint: The number of nodes in the nonempty perfect binary tree is 2 raised to the power of height - 1) (/** returns true if the tree is a perfect binary tree, boolean isPerfectBST() **/)
3) (10 points) The method isHeap determines whether a binary tree is a heap. The implementation this method given below contains a few bugs. Find these bugs and correct them. public class BinaryTree extends AbstractTree public Boolean isHeap O if (isEmpty O) ir CgetLeft o.isEmpty O ll getLeft O.getKey O.isLT (getk ey O) if CgetRight O.isEmpty Oll getRight O.getLey O.isLT return getLeft О.isHcap ( ) && getRight O.isHeap О; return true; return false; retuen false; getKey O)
i need help to modify this Tree class to include a method leavesCount that returns the number of leaves in a binary tree. (NOTE: Complete leavesCount and leavesCountHelper methods in the Tree class). I already have the test class. java class TreeNode< T extends Comparable< T > > { TreeNode< T > leftNode; T data; TreeNode< T > rightNode; public TreeNode( T nodeData ) { data = nodeData; leftNode = rightNode = null; } public void insert( T insertValue )...
Create a binary tree class. -Data array field (private) -Count field Add method(data) -The add method takes a data point, add it to the count position in the array then increases the count. Print method(void) -Prints all the fields in the tree. C++, no libraries are allowed (only )
A binary tree is constructed of nodes that are instances of the following class: public class Node public int val public Node left public Node right) Consider the following method public static Node mystery Node root) rootghtanul return root else return mystery root ) You consult Professor Kennedy and hegves an opinion about what the method does when passed a reference to the root node of a binary tree. Assuming he is correct what does the mystery function do? it...
in python
11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree You will also need to implement a Node class. This class will not be tested, but is needed to implement the BST. Your BST must implement the following methods. You are free to implement additional helper methods. It is recommended you create your own helper methods Constructor: Creates an Empty Tree String Method: Returns the string "Empty Tree" for an empty tree. Otherwise, returns...
In Java: Given the following binary tree class, write a recursive method called size() which will find the number of nodes in the subtree rooted at the current node: class myBinaryTree{ int myValue; myBinaryTree left; myBinaryTree right; myBinaryTree(int inValue) {myValue = inValue;} public int size(){ <CODE WRITTEN HERE> } }
Binary Tree Template Write your own version of a class template that will create a binary tree that can hold values of any data type. Demonstrate the class with a driver program. Place your binary tree template in it's own header file, Btree.h. Include methods for the following: inserting new values into the tree removing nodes from the tree searching the tree returning the number of nodes in the tree displaying the contents of the tree using preorder traversal Your...