Question: 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

 In java please Problem 2: Determine whether a tree is a

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!