Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this problem, we will implement a Complete tree using nodes. For example, in C++ the node and class definitions would look like this: struct

image text in transcribed

image text in transcribed

image text in transcribed

For this problem, we will implement a Complete tree using nodes. For example, in C++ the node and class definitions would look like this: struct Node int data; Node left; Node* right; Node parent; class CompleteTree C Node* root; You will need to implement the following operations on complete trees: fromArray which creates nodes for a complete tree represented by the given array toArray which returns the array representation of the complete tree isBST which returns true if the complete tree is a Binary Search Tree preOr postOrder which prints a post-order traversal of the tree numNodesInLookup which prints the number of nodes visited when looking up the given der which prints a pre-order traversal of the tree value. For example, in C++,the function headers would be the following class CompleteTree Node* root; public CompleteTree) void fromArray (vector list) vector int> toArray bool isBSTO void pre0rder O void postorder int numNodesInLookup(int value) J; Input 100, denoting the number of nodes in the The next line will consist of n integers that make up the values to be stored in the 10, denoting the number of commands "pre- The first line contains an integer n,0 S tree tree . The third line contains an integerm,0Sm in the following lines. The next m lines have one of the following commands "toArray", "isBST Order", "post Order", "numNodesInLookup") per line. Constraints In this proble, a binary search tree must have unique values. You can assume the value given to "numNodesInLookup" is in the tree. numNodesInLookup should try to look at as few nodes as possible. This means that if the tree is a Binary Search Tree, it should use binary search. If the tree is not a binary tree, use level-order traversal Output "toArray" will print out the array representation of the complete tree "isBST" wil print out either "or false" ."preOrder and "postOrder" will print out the order they visit each node respectively numNodesInLookup" will print out an integer Sample Input 1 10 1 2 3 456789 10 4 isBST pre0rder toArray numNodesInLookup 4 Sample Output 1 false 1 2 4 89510 3 67 1 2 3 4 5 6 7 89 10 4 Sample Input 2 12 100 53 172 24 64 150 200 12 33 60 98 130 isBST postorder numNodesInLookup 98 Sample Output 2 true 12 33 24 60 98 64 53 130 150 200 172 100

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

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

Use brainstorming effectively.

Answered: 1 week ago

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago