Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.*; public class PoD { //============================================================================= /** * Returns true if the binary tree is a binary search tree (BST) * * @param Tree

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

import java.util.*; public class PoD { //============================================================================= /**  * Returns true if the binary tree is a binary search tree (BST)  *  * @param Tree BinaryTree of interest  * @return boolean (true if BST)  */   public static boolean isBST(BinaryTree tree) { /* Check if the binary tree is a BST: For all nodes, all left descendants are less than the value stored in the node and all right descendants have greater data values. d / \ (d) */ boolean meetsCriteria; return meetsCriteria; } //============================================================================= public static void main(String[] args) { Scanner in = new Scanner(System.in); //int i = in.nextInt(); //int j = in.nextInt(); BinaryTree newTree = buildTree(in); boolean isBinarySearchTree = isBST(newTree); in.close(); if (isBinarySearchTree) { System.out.println("This is a binary search tree"); } else { System.out.println("NOT a binary search tree"); } System.out.print("END OF OUTPUT"); } /**  * Reads in data to form a binary tree:  * N ( L R )  * N = node data  * L = Left binary tree data (possibly of same form)  * R = Right binary tree data (possibly of same form)  * expects all nodes until reaching null  *  * e.g. input: a ( b ( null null ) c ( null null ) )  * creates tree:  * a  * / \  * b c  */   public static BinaryTree buildTree(Scanner in) { String data = in.next(); BinaryTree left = null; BinaryTree right = null; if (data.equals("null")) { return null;} if (!in.next().equals("(")) { System.out.println("BAD INPUT: (L"); } left = buildTree(in); right = buildTree(in); if (!in.next().equals(")")) { System.out.println("BAD INPUT: R)"); } return new BinaryTree(data, left, right); } }
Today you are going to whether or not a binary tree is a binary search tree. Binary search tree Recall that a binary search tree is a binary tree in which for all nodes, all left descendants are less than the value stored in the node and all right descendants have greater data values. Details Download the ZIP files named FilesNeeded.zip for use in Intellij.When you are happy with your solution, upload the files into the src folder and run You are going to finish off PoD.java to finish the isBST method. Input The main method (already completed) creates a binary tree and passes that binary tree to the isBST method. Processing You are going to complete the details of isBST method. Details of each method and their expected parameters are described in the Javadoc comments preceding it. The method should return true if the binary tree is a binary search tree return false if not

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

Students also viewed these Databases questions

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago

Question

2 The main characteristics of the market system.

Answered: 1 week ago