Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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 Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

What aspects would it be impossible to capture?

Answered: 1 week ago

Question

Enhance your words with effective presentation aids

Answered: 1 week ago