Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java please Problem 2: Determine whether a tree is a binary search tree (a) Design and implement a Java program that determines whether a

image text in transcribed

In java please

Problem 2: Determine whether a tree is a binary search tree (a) Design and implement a Java program that determines whether a given tree is a binary search tree (BST). Input. The input is a textual representation of a binary tree in the same format as in the problem above. Specifically, the first line contains one integer, n, the number of nodes in the tree. The next n lines represent the n nodes of the tree. Each of these lines consists of four space-separated tokens. The first token is a string representing the label of the node. The second token is an integer representing the value of the node. The third and the fourth tokens are strings representing respectively the labels of the left and right children of the current node. The string "NONE" is used in place of the third and/or fourth tokens if a node does not have a left and/or a right child. Sample input A 5 BC B 3 NONE NONE C 4 NONE NONE Output. The output consists of a single line. If the given tree is a BST, this line is "The tree IS a binary search tree." Otherwise, the output is "The tree IS NOT a binary search tree. Sample output (for the above input): The tree IS NOT a binary search tree (b) State what the time complexity of your program is and explain why

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions