Question: Need help with a binary search tree check in C++! Here is the prompt: Input: You will be given a series of trees specified in

Need help with a binary search tree check in C++!

Here is the prompt:

Input:

You will be given a series of trees specified in Breadth First Search order from standard input:

N N_0 N_1 ... N_N-1

The first number of each line is the number of nodes in the binary tree.

The remaining numbers are the values for each node.

Any nodes with the value -1 are considered empty nodes (ie. they don't exist).

Output:

For each tree, you should output the message:

Tree N is a BST

if the binary tree is a binary search tree. Otherwise, you should output:

Tree N is not a BST

Note, N is the tree number in the order in each it was read (starting from 1).

Example

Given the following input:

2 20 20 3 20 -1 20 14 8 3 10 1 6 -1 14 -1 -1 4 7 -1 -1 13

Your program should output the following:

Tree 1 is a BST Tree 2 is not a BST Tree 3 is a BST

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!