public static int nbLeaf(BT bt, T e):
This method counts and returns the number of leaf nodes that contain the data e. You should use the find, isLeaf and maybe otherBT methods for counting
method isLeaf
public boolean isLeaf (){
if (root==null) return false;
else
if ((current.left==null)&&(current.right==null))
return true;
else return false; }
method find :
public boolean find(Relative rel){
switch (rel) {
case Root: // Easy case
current = root;
return true;
case Parent:
if(current == root) return false;
current = current.parent;
return true;
case LeftChild:
if(current.left == null) return false;
current = current.left;
return true;
case RightChild:
if(current.right == null) return false;
current = current.right;
return true;
default:
return false;
}
}
public static int nbLeaf(BT bt, T e)
{
// if tree is empty
if( bt == null )
return 0;
// if tree is not empty
else
{
// get no of required leaf in left subtree
int l = nbLeaf( bt.left , e );
// get no of required leaf in right subtree
int r = nbLeaf( bt.right , e );
// if the current node is the required leaf node
// assuming date is the feied storing date
if( isLeaf(bt) && bt.date == e )
return l + r + 1;
// if the current node is not the required leaf node
else
return l + r;
}
}
public static int nbLeaf(BT bt, T e): This method counts and returns the number of leaf...
Java binary search tree Add the following print method to the binary search tree class created in class (on D2L). This method should print all the nodes in the tree in level order (root first, then all children of root, then all children of those). Ensure your method runs in O(N), include comments to show how it conforms to this rule. Method header: public void printInLevelOrder() public class BinarySearchTree<E extends Comparable<? super E>> { private Node root; public BinarySearchTree() {...
Please I need help ASAP Java Programing: Binary Search Tree Fully implement the BST class in Listing 25.4 (on page 961 of the 11th Edition of the text). Design and write a (main) driver program to completely test every method in the BST class to ensure the class meets all its requirements. You should read the Listing 25.5: TestBST.java for an idea of what your program should look like. Listing 25.4 BST.java public class BST> extends AbstractTree { protected TreeNode...
Question - modify the code below so that for a node, the value of every node of its right subtree is less the node, and the value of each node of its left subtree is greater than the node. - create such a binary tree in the Main method, and call the following method: InOrder(Node theRoot), PreOrder(Node theRoot), PostOrder(Node theRoot), FindMin(), FindMax(), Find(int key) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;...
Using the following implementation of Tree class Node { public int iData; // data item (key) public double dData; // data item public Node leftChild; // this node's left child public Node rightChild; // this node's right child public void displayNode() // display ourself { System.out.print('{'); System.out.print(iData); System.out.print(", "); System.out.print(dData); System.out.print("} "); } } // end class Node //------------------------------------------------------------------ import java.io.IOException; import java.util.Stack; public class Tree { private Node root; // first node of tree // ------------------------------------------------------------- public Tree() // constructor { root = null; }...
write a new test program called RemoveDuplicates.java. The program reads text input from keyboard or a text file and adds the words to a BST. The program then traverses the BST and prints out the words in order (based on ASCII/UNICODE order) on the screen (or to output text file). Note that you may need to make some changes to BST.java. Sample test: ----jGRASP exec: java -ea removeDuplicates Original Text: a B 2 n w C q K l 0...
Can Anyone help me to convert Below code to C++! Thanks For example, in C++, the function headers would be the following: class MaxHeap { vector<int> data; public: MaxHeap() { // ... } int size() { // ... } int maxLookup() { // ... } void extractMax() { // ... } void insert(int data) { // ... } void remove(int index) { // ... } }; ======================== import java.util.Arrays; import java.util.Scanner; public class MaxHeap { Integer[] a; int size; //...
1) Extend the Binary Search Tree ADT to include
a public method leafCount that returns the number of leaf nodes in
the tree.
2) Extend the Binary Search Tree ADT to include a
public method singleParent-Count that returns the number of nodes
in the tree that have only one child.
3) The Binary search tree ADT is extended to
include a boolean method similarTrees that receives references to
two binary trees and determines whether the shapes of the trees are...
add/ remove any methods to the program. please post new code
and output
Min Heap:
public class MinHeap {
private int[] Heap; private int size; private int
maxsize;
private static final int FRONT = 1;
public MinHeap(int maxsize) {
this.maxsize = maxsize;
this.size = 0;
Heap = new int[this.maxsize + 1]; Heap[0] =
Integer.MIN_VALUE;
}
private int parent(int pos) {
return pos / 2; }
private int leftChild(int pos) {
return (2 * pos); }
private int rightChild(int pos) {...
PLEASE HELP! The assignment details are in the *noted part of the code. I REALLY need help. import java.util.LinkedList; public class TwoDTree { private TwoDTreeNode root; private int size; public TwoDTree() { clear(); } /** * Returns true if a point is already in the tree. * Returns false otherwise. * * The traversal remains the same. Start at the root, if the tree * is not empty, and compare the x-coordinates of the point passed * in and...
From the code below with Binary Search Tree recurrence T(n)=?
use the recursion method and substitution method to solve the
recurrence. Find the tightest bound g(n) for T(n) you can for which
T(n)= O(g(n)). Explain your answer and use recursion tree
method.
void insert(int data) {
struct node *tempNode = (struct node*) malloc(sizeof(struct node));
struct node *current;
struct node *parent;
tempNode->data = data;
tempNode->leftChild = NULL;
tempNode->rightChild = NULL;
//if tree is empty
if(root == NULL) {
root = tempNode;...