Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java: Code Skeleton // node class for a binary tree class BinaryNode { int key; BinaryNode left, right; // constructor public BinaryNode(int key) {

image text in transcribedUsing Java:

Code Skeleton

// node class for a binary tree class BinaryNode { int key; BinaryNode left, right;

// constructor public BinaryNode(int key) { this.key = key; left = right = null; } }

// a binary search tree class public class BinarySearchTree { BinaryNode root;

// constructor public BinarySearchTree() { root = null; }

/* returns the range(difference between the highest and lowest) of values in a binary search tree.*/ int getRange(BinaryNode node) { //write here }

/*Returns the number of nodes in binary search tree that have keys in range [low, high]. range includes low and high*/ int inRangeCount(BinaryNode node, int low, int high) { // write here }

public static void main(String args[]) {

BinarySearchTree bst = new BinarySearchTree(); bst.root = new BinaryNode(3); bst.root.left = new BinaryNode(1); bst.root.right = new BinaryNode(6); bst.root.left.left = new BinaryNode(0); bst.root.left.right = new BinaryNode(2);

System.out.println(bst.getRange(bst.root)); System.out.println(bst.inRangeCount(bst.root,0,3)); } }

Binary Search Tree For this homework, you need to write two methods related to binary search trees. The code skeleton is provided in BinarySearchTree.java file. int getRange (BinaryNode node) returns the range (difference between the highest and lowest) of values in a binary search tree. In the following example (root is the node with key 12), getRange(root) should return 22 -5- 17. You can return -1 if the tree is null. (50 points) 12 10 16 int inRangeCount (BinaryNode node, int low, int high) returns the number of nodes in binary search tree that have keys in range [low, high]. Note that the range includes low and high. In the above example tree, inRangeCount(root, 10,13) should return 3, since there are 3 nodes whose keys are in range [10,13]. (50 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Question Can life insurance be used in a Keogh (HR 10) plan?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago