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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started